Я создал простого бота-телеграммы в python
, который связывается с DialogFlow
.Это код
#!/usr/bin/env python
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
import apiai, json
updater = Updater (token = '')
dispatcher = updater.dispatcher
# Processing commands
def startCommand (bot, update):
bot.send_message (chat_id = update.message.chat_id, text = '')
def textMessage (bot, update):
request = apiai.ApiAI (''). text_request()
request.lang = 'it'
request.session_id = 'TestBot'
request.query = update.message.text
responseJson = json.loads ( request.getresponse (). read (). decode ('utf-8'))
response = responseJson ['result'] ['fulfillment'] ['speech']
if response:
bot.send_message (chat_id = update.message.chat_id, text = response)
else:
bot.send_message (chat_id = update.message.chat_id, text = '')
start_command_handler = CommandHandler ('start', startCommand)
text_message_handler = MessageHandler (Filters.text, textMessage)
dispatcher.add_handler (start_command_handler)
dispatcher.add_handler (text_message_handler)
updater.start_polling (clean = True)
updater.idle ()
Когда я пытаюсь его запустить, у меня появляется эта ошибка
Traceback (most recent call last):
File "testbot.py", line 2, in <module>
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
File "/usr/local/lib/python2.7/dist-packages/python_telegram_bot-12.0.0b1-py2.7.egg/telegram/ext/__init__.py", line 28, in <module>
from .updater import Updater
File "/usr/local/lib/python2.7/dist-packages/python_telegram_bot-12.0.0b1-py2.7.egg/telegram/ext/updater.py", line 33, in <module>
from telegram.utils.webhookhandler import (WebhookServer, WebhookAppClass)
File "/usr/local/lib/python2.7/dist-packages/python_telegram_bot-12.0.0b1-py2.7.egg/telegram/utils/webhookhandler.py", line 27, in <module>
from tornado.httpserver import HTTPServer
File "/usr/local/lib/python2.7/dist-packages/tornado-6.0.3-py2.7-linux-x86_64.egg/tornado/httpserver.py", line 144
def __init__(self, *args: Any, **kwargs: Any) -> None:
^
SyntaxError: invalid syntax
Я уже установил pip
таким образом
sudo apt-get install python-pip