def chatter(bot,update):
chat_id = update.message.chat_id
message = update.message.text
if message == 'foto':
bot.sendChatAction(chat_id=chat_id, action=telegram.ChatAction.UPLOAD_PHOTO)
bot.sendPhoto(chat_id=chat_id, photo='https://unsplash.it/600?random')
else:
k = aiml.Kernel()
k.learn("std-startup.xml")
k.respond("sara")
k.setBotPredicate("name", "Sara")
k.setBotPredicate("anyo_nacimiento", "2015")
k.setBotPredicate("edad", str(date.today().year-2015) )
k.setBotPredicate("botmaster", 'Alexander' )
k.setBotPredicate("nombre_bot", 'Sara' )
k.setBotPredicate("birthday", '17/12/2015' )
bot.sendChatAction(chat_id=chat_id, action=telegram.ChatAction.TYPING)
response = k.respond(message)
#bot.sendMessage(chat_id, text=response)
tts = gTTS(text=response, lang='es')
file = str(chat_id) + str(time.time()) + '.ogg'
tts.save(file)
bot.sendVoice(chat_id=chat_id, voice=open(file, 'rb'))
os.remove(file)
评论列表
文章目录