Closed Nyako01 closed 6 years ago
Hello Oky12,
if you want to send a message with the method sendMessage()
you have to know the _Telegram user/chatid as I explained here:
https://github.com/shurillu/CTBot/blob/master/REFERENCE.md#ctbotsendmessage
For example, if your bot need to send messages to your mobile telegram account, you can modify the echobot example in this way:
#include "CTBot.h"
CTBot myBot;
void setup() {
Serial.begin(115200); // initialize the serial
myBot.wifiConnect("mySSID", "myPassword"); // connect to the WiFi Network
myBot.setTelegramToken("myTelegramBotToken"); // set the telegram bot token
}
void loop() {
TBMessage msg; // a variable to store telegram message data
// if there is an incoming message...
if (myBot.getNewMessage(msg)) {
// ...forward it to the sender
myBot.sendMessage(msg.sender.id, msg.text);
Serial.println(msg.sender.id); // <-------------- ADD THIS
}
delay(500); // wait 500 milliseconds
}
Running this sketch and sending a message with your mobile to the bot, it will echo the message and print on the serial your mobile telegram account ID. Just write down that number ad use it in your sketches in this way:
sendMessage(yourID, yourMsg)
Let me know if it resolve your issue. If yes, please close the issue and if you like the library, could you star it?
Stefano
I follow your instructions and work, so if I want to send a message with sendMessage (), it must have a chat ID. Right? but to get chat ID must send a message to bot and then save chat ID to another variable. -_-
Its ok. I will save the chat id in eeprom
Thanks for Help me
hi i have a project Iot. in my issue i cannot sending messages to telegram bot. for example I want to send esp8266 status messages to telegram bots.
but the messages not sended i try check library with debugging and i found this
please help my issue I can only send messages if there is an incoming message from the bot