#include "CTBot.h"
CTBot bot;
int LED = 2;
String token = "6028107999:AAEiyN8rS8bWHF9ULba4l2WaKXbeIrXt4w4";
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Mulai");
pinMode(LED, OUTPUT);
bot.wifiConnect("Wokwi-GUEST","");
bot.setTelegramToken(token);
if(bot.testConnection()){
Serial.println("Terhubung");
}
else{
Serial.println("Gagal Terhubung");
}
}
void loop() {
TBMessage chat;
if(bot.getNewMessage (chat)){
Serial.println("Ada pesan masuk dari "+String(chat.sender.id));
Serial.println("----> "+String(chat.text));
if(chat.text.equalsIgnoreCase("A")){
digitalWrite(LED, HIGH);
Serial.print("Led Menyala");
bot.sendMessage (chat.sender.id,"Led nyala boss");
Serial.println(" <Berhasil dijawab>");
}
else if (chat.text.equalsIgnoreCase("B")){
digitalWrite(LED, LOW);
Serial.print("Led Mati");
bot.sendMessage (chat.sender.id,"Led sudah mati boss");
Serial.println(" <Berhasil dijawab>");
}
else{
bot.sendMessage (chat.sender.id,"Kamu bukan bos saya");
}
}
// put your main code here, to run repeatedly:
/*digitalWrite(LED, HIGH);
delay(500); // this speeds up the simulation
digitalWrite(LED, LOW);
delay(500);*/
}