F
F
Foxrey2020-08-19 23:33:59
Python
Foxrey, 2020-08-19 23:33:59

How to make the telegram chat bot respond to my message with what I wrote to him?

chat bot instead of what I wrote to him, in theory he should copy my message and send

import requests
API_link = ' https://api.telegram.org/bot1153670351:AAH7AOmF6Q4... '

updates = requests.get(API_link+'/ getUpdates').json()

message = updates["result"][0]["message"]
chat_id = message["from"]["id"]
text = message["text"]

send_message = requests.get( API_link + f"/sendMessage?chat_id={chat_id}&text=You wrote {text}")

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
toshk9, 2020-08-19
@Foxrey

bot.send_message(message.chat.id, message.text)
the first argument is the id of the chat with the bot
the second argument or the text= argument is the text of the bot's response message
here is the complete code block:
bot = telebot.TeleBot(token)
@bot.message_handler (content_types=['text'])
def handle_message(message):
bot.send_message(message.chat.id, message.text)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question