Example taken from https://groosha.gitbooks.io/telegram-bot-lessons/content/chapter1.html

# -*- coding: utf-8 -*- import config import telebot bot = telebot.TeleBot(config.token) @bot.message_handler(content_types=["text"]) def repeat_all_messages(message): # НазваниС Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΈ Π½Π΅ ΠΈΠ³Ρ€Π°Π΅Ρ‚ Π½ΠΈΠΊΠ°ΠΊΠΎΠΉ Ρ€ΠΎΠ»ΠΈ, Π² ΠΏΡ€ΠΈΠ½Ρ†ΠΈΠΏΠ΅ bot.send_message(message.chat.id, message.text) if __name__ == '__main__': bot.polling(none_stop=True) 

In message.chat.id - contains chat_id for example 123456789

I need to send a message to the user.

In the browser I type:

 https://api.telegram.org/bot<Ρ‚ΠΎΠΊΠ΅Π½>/sendMessage?chat_id=123456789&text=Hello 

Answer

 {"ok":false,"error_code":400,"description":"Bad Request: chat not found"} 

Where to dig?

  • Are you sure you specified chat_id ? The user must activate the bot with the command /start and only after that the bot will be able to write to him. - Pavel Durmanov
  • I see that the chat is not found but took via getUpdates - masterbob

1 answer 1

 Π’ вашСм случаС активация Π±ΠΎΡ‚Π° происходит ΠΏΡ€ΠΈ Π²Π²ΠΎΠ΄Π΅ /text @bot.message_handler(content_types=["text"]) 

Further write the text to the bot and the written text should return.

Try again so add msg =:

 @bot.message_handler(content_types=["text"]) def repeat_all_messages(message): # НазваниС Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΈ Π½Π΅ ΠΈΠ³Ρ€Π°Π΅Ρ‚ Π½ΠΈΠΊΠ°ΠΊΠΎΠΉ Ρ€ΠΎΠ»ΠΈ, Π² ΠΏΡ€ΠΈΠ½Ρ†ΠΈΠΏΠ΅ msg = bot.send_message(message.chat.id, message.text) 
  • I understand that. Activation of the bot occurs above as you wrote. I get id_chat with (user). But I need then, after a certain time, to this specific user to send a message, for example, from a script in php. Can I send it via ' api.telegram.org/bot <<i> </ i> / / ... ' - masterbob
  • one
    The answer is completely wrong, content_types accepts the type of the message, not the command, msg=... will give nothing. If you want to catch only text, content_types=['text'] can be omitted, since this is a standard value. - Pavel Durmanov
  • msg is the Telegtam (response) response about the execution result - masterbob
  • That does not solve the problem. - Pavel Durmanov
  • SINGLELY NO! - masterbob