#include "CTBot.h";
#include <WiFi.h>
#include <WiFiClient.h>
CTBot mybot;
String ssid = "Wokwi-GUEST";
String pass = "";
String token = "5733814903:AAHFcOkj1PN_VRSzv6bvll_licL95wJXxZc";
const int id = 987119589;
int led = 4;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(led, OUTPUT);
Serial.println("Memulai telegram bot");
mybot.wifiConnect(ssid, pass);
mybot.setTelegramToken(token);
if(mybot.testConnection())
Serial.println("koneksi berhasil");
else
Serial.println("koneksi gagal");
}
void loop() {
// put your main code here, to run repeatedly:
TBMessage msg;
if(mybot.getNewMessage(msg))
Serial.println("pesan masuk : "+msg.text);
String pesan = msg.text;
if(pesan=="on"){
digitalWrite(led, HIGH); //led nodemcu menyala
mybot.sendMessage(id, "Led Menyala");
}
else if (pesan=="off"){
digitalWrite(led, LOW); //led nodemcu mati
mybot.sendMessage(id, "Led Mati");
}
}