Closed indirwanadi closed 4 years ago
Hello indirwanadi,
the main problem in your code should be: you don't provide the Telegram ID of the recipient.
When you call myBot.sendMessage(msg.sender.id, "Sistem terhubung >_<");
, the msg.sender.id
MUST have the recipient Telegram ID.
So
sendMessage
method.To retrieve your Telegram ID, load this code:
#include "CTBot.h"
CTBot myBot;
String ssid = "mySSID"; // REPLACE mySSID WITH YOUR WIFI SSID
String pass = "myPassword"; // REPLACE myPassword YOUR WIFI PASSWORD, IF ANY
String token = "myToken" ; // REPLACE myToken WITH YOUR TELEGRAM BOT TOKEN
void setup() {
Serial.begin(115200);
Serial.println("Starting TelegramBot...");
myBot.wifiConnect(ssid, pass);
myBot.setTelegramToken(token);
if (myBot.testConnection())
Serial.println("\ntestConnection OK");
else
Serial.println("\ntestConnection NOK");
}
void loop() {
TBMessage msg;
if (myBot.getNewMessage(msg))
myBot.sendMessage(msg.sender.id, (String)msg.sender.id);
delay(500);
}
Once loaded and running, send a message to the bot with your account: it should answer you by your Telegram ID (a number).
Now put your Telegram ID in the sendMessage: myBot.sendMessage(YOUR_TELEGRAM_ID_HERE, "Sistem terhubung >_<");
and you should receive a message when the bot is online (using your code, obviously).
Let me know if it solve the problem (and maybe put a star to this library).
Cheers
Stefano
Oh Thank God, the method you provide solve the problem and now i can implement it to my code. Thank you very much, sir.
Good!
i want to get a notification sent to telegram chat room when system is online and i can't get that method works by this code: TBMessage msg;
// check if all things are ok if (myBot.testConnection()) { myBot.sendMessage(msg.sender.id, "Sistem terhubung >_<"); Serial.println("\ntestConnection OK"); }
else Serial.println("\ntestConnection NOK");