Не удается получить сообщение из телеграммы (телетарафона) - PullRequest
0 голосов
/ 19 января 2020

Я хочу сделать автоответчик с телетоном python. Но когда я бегу, он не может получить сообщение и не может ответить на мое сообщение.

Это мой код. Любой может помочь мне, пожалуйста

def chatbot_response(msg):
ints = predict_class(msg, model)
res = getResponse(ints, intents)
return res

if __name__ == '__main__':
# Create the client and connect
# use sequential_updates=True to respond to messages one at a time
client = TelegramClient(session_file, api_id, api_hash, sequential_updates=True)

@client.on(events.NewMessage(incoming=True))
async def handle_new_message(event):  
    if event.is_private:  # only auto-reply to private chats
        from_ = await event.client.get_entity(event.from_id)  
        if not from_.bot:  # don't auto-reply to bots
            msg = events.NewMessage(incoming=True)
            if msg!='':
                message= cchatbot_response(msg)
                print(time.asctime(), '-', event.message)  # optionally log time and message
                time.sleep(1)  # pause for 1 second to rate-limit automatic replies
                await event.respond(message)


print(time.asctime(), '-', 'Auto-replying...')
client.start(phone, password)
client.run_until_disconnected()

1 Ответ

0 голосов
/ 19 января 2020

Я могу запустить ваш код без этих строк

message = cchatbot_response(msg)
print(time.asctime(), '-', event.message)  # optionally log time and message
time.sleep(1)  # pause for 1 second to rate-limit automatic replies

Пожалуйста, проверьте функцию cchatbot_response.

Кроме того, я назвал эту строку

client.start(phone, password)

как this

client.start()

Он запросил у меня номер телефона и пароль, но больше не упоминал.

...