Forums

Telegram bot

Hello, I've successfully followed the great post here: https://blog.pythonanywhere.com/148/ and I would like to tweak it a bit. Instead of using the nltk chatbot, I want to link to an Apiai bot. I am trying to adapt this tutorial:https://chatbotnewsdaily.com/build-a-facebook-messenger-chat-bot-in-10-minutes-5f28fe0312cd but so far to no success. I would gladly welcome any help or pointers. Many thanks ;)

Try it and see.

Hi, thanks for your reply. I did try, I pip install the Apiaa, I imported it and I replace this bit: - " text = update["message"]["text"] chat_id = update["message"]["chat"]["id"] bot.sendMessage(chat_id, "From the web: you said '{}'".format(text)) return "OK"" with this bit: - # prepare API.ai request req = ai.text_request() req.lang = 'en' # optional, default value equal 'en' req.query = message # get response from API.ai api_response = req.getresponse() responsestr = api_response.read().decode('utf-8') response_obj = json.loads(responsestr) if 'result' in response_obj: response = response_obj["result"]["fulfillment"]["speech"] reply(sender, response)"

I just ended up with many errors in the console. I do am a beginner so I was going along to see what I need to fix, but If you or somebody on the forum dealt with this kind of issue or saw a way to make it work, it would be great. Thanks

What kind of issue? You've told us nothing about the issue you're having.

Hello Glenn, I have tweaked a bit and now I have error about undefined variables (undefined json for ex). But I have trouble identifying what are those supposed to do with telebot and so how to define them properly. I am sorry this isn't very clear, but if you don't mind taking a look I have made a gists of it(without the token codes): https://gist.github.com/thouni2009/0a2074c01dc6af76ec021d0ef332dd9d cheers

It's hard to debug that without knowing the exact line that's showing the error, but I did notice that at line 41 you're using a variable called "sender", which doesn't seem to be defined anywhere, and you don't have import json at the top of your file.

you're right! I imported the json and now it works. Thanks a bunch :D

No problem, glad to help!