#include "CTBot.h"
CTBot myBot;
String ssid = "Wokwi-GUEST";
String pass = "";
String token = "5940812729:AAGDzUIuThEDBlgABqE7gwASQ9UihdSSGjo";
const int lampu = LED_BUILTIN;
void setup() {
Serial.begin(115200);
Serial.println("Starting TelegramBot...");
myBot.wifiConnect(ssid, pass);
myBot.setTelegramToken(token);
if (myBot.testConnection())
Serial.println("\nKoneksi Ke Telegram BOT Berhasil!");
else
Serial.println("\nTidak Terkoneksi Ke Telegram BOT");
pinMode(lampu, OUTPUT);
digitalWrite(lampu, HIGH);
}
void loop() {
TBMessage msg;
if (myBot.getNewMessage(msg)) {
if (msg.text.equalsIgnoreCase("On")) { //Perintah dari telegram ke perangkat
digitalWrite(lampu, LOW); //Lampu dihidupkan
Serial.println("\nLampu Dihidupkan");
myBot.sendMessage(msg.sender.id, "The Led is now ON"); //Balasan dari perangkat ke Bot Telegram
}
else if (msg.text.equalsIgnoreCase("Off")) { //Perintah dari telegram ke perangkat
digitalWrite(lampu, HIGH); //Lampi dihidupkan
Serial.println("\nLampu Dimatikan");
myBot.sendMessage(msg.sender.id, "The Led is now OFF"); //Balasan dari perangkat ke Bot Telegram
}
else { // otherwise...
// generate the message for the sender
String reply;
reply = (String)"Welcome " + msg.sender.username + (String)". Silahkan gunakan perintah On atau Off.";
myBot.sendMessage(msg.sender.id, reply); // and send it
}
}
delay(500);
}