Skip to content

Instantly share code, notes, and snippets.

@rcotrina94
Last active May 10, 2016
Embed
What would you like to do?
Telegram.bot
# -*- coding: utf-8 -*-
import telebot
from telebot import types
USER_WELCOME = "Bienvenido al servicio de HomeHub."
USER_REGISTERED = "{}, te hemos registrado en nuestro sistema."
TOKEN = "123456789:TOKEN4529424024-ConfiguraTuTokenXDXDXDXD"
bot = telebot.TeleBot(TOKEN)
# class Contact(object):
rcadmin = {
'first_name': 'Richard',
'last_name': 'Cotrina',
'phone_number': '+51999999999'
}
@bot.message_handler(commands=['start'])
def send_welcome(message):
bot.send_message(message.chat.id, USER_WELCOME)
bot.send_message(message.chat.id, USER_REGISTERED.format(message.chat.first_name))
@bot.message_handler(regexp='[Hh][Oo][Ll][Aa][!\?]*')
def say_hello(message):
bot.send_message(message.chat.id, "Hola.")
@bot.message_handler(commands=['help', 'ayuda'])
def help_message(message):
bot.send_message(message.chat.id, u"Aquí debe mostrarse un mensaje de ayuda")
@bot.message_handler(func=lambda m: True)
def echo_all(message):
# bot.send_chat_action(message.chat.id, action='typing')
bot.reply_to(message, u"No te entiendo ¿Qué se supone que significa {}?".format(message.text))
# Log all messages:
def handle_messages(messages):
for message in messages:
print "{}: {}".format(message.chat.first_name, message.text)
bot.set_update_listener(handle_messages)
bot.polling()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment