3
I don’t know if that kind of question is welcome here, but come on:
I’m developing a chatbot on python
and chose the library chatterbot
because of the processamento de linguagem natural
, by the ability to use more than one corpus and mainly by the ability of the bot to learn to converse with the user himself.
The bot made with the chatterbot
wheel by CMD
, but I’d like to put it on telegram
.
I implemented the answer code below and as much as my chatbot is working on the computer, on Telegram it does not respond to messages. Could someone help me?
import os
from chatterbot import ChatBot
from chatterbot.trainers import ListTrainer
from telegram.ext import Updater, MessageHandler, Filters
# Define a função que responderá no Telegram
def response(update, context):
bot_response = bot.get_response(update.message.text)
update.message.reply_text(bot_response)
def main():
# Inicia o bot do Telegram
updater = Updater("o meu token ta aqui, eu juro")
# Pega o disparador do Telegram
dp = updater.dispatcher
# Adiciona a função ao bot
dp.add_handler(MessageHandler(Filters.text, response))
if __name__ == '__main__':
main()
bot = ChatBot("Futaba")
trainer = ListTrainer(bot)
for arquivos in os.listdir('arquivos'):
chats = open('arquivos/' + arquivos, 'r', encoding="utf8").readlines()
trainer.train(chats)
print("Hey, meu nome é Futaba e você pode se sentir confortável para conversar comigo mesmo que conversar não seja lá a coisa mais confortável pra você.")
response = bot.get_response("Hey!")
print(response)
while True:
resq = input('Você: ')
resp = bot.get_response(resq)
if float(response.confidence) > 0.5:
print('Futaba: ' + str(resp))
else:
print('Como você tem se sentido?')
Of course I do. Chatterbot does not define how you will get the message to be handled, so you just need to integrate with the Telegram API and get the messages from it (and send the reply from it as well).
– Woss
Aaaah, I got it! So I can continue using chatterbot to develop the bot, I don’t need to use the python-Telegram-bot framework, just use the same Telegram API directly.
– Mariana Bayonetta
But it’s obvious that he won’t answer Telegram, you didn’t even put the bot to read his messages. Have you read the documentation cited? Did you see that you need to call for other methods than what I quoted in the answer? By the way, with your edition you invalidated my reply, so much so that you removed the acceptance, this should be avoided here on the site and the editing should be reversed. If there is another problem that has not been addressed here you should open a new question.
– Woss
Okay, man, it was just a question but I already solved it.
– Mariana Bayonetta