#include "CTBot.h"
CTBot robot;
int relay=4;

void setup() {
  Serial.begin(115200);
  pinMode(relay,OUTPUT);
  digitalWrite(relay,HIGH);
  robot.wifiConnect("DUWI ARSANA.COM", "PASSWORD");
  robot.setTelegramToken("927708982:AAHE0kbDaoXgiJh97wmMTkH4kDsTbHaRr8");
  if(robot.testConnection())
  Serial.println("Terhubung!");
  else
  Serial.println("Error!");

}

void loop() {
  TBMessage pesan;

  if(robot.getNewMessage(pesan)){
    Serial.print("Ada pesan Masuk : ");
    Serial.println(pesan.text);
    if(pesan.text.equalsIgnoreCase("RELAY ON")){
      digitalWrite(relay,LOW);
      robot.sendMessage(pesan.sender.id,"Relay Menyala");
    }
    else if(pesan.text.equalsIgnoreCase("RELAY OFF")){
      digitalWrite(relay,HIGH);
      robot.sendMessage(pesan.sender.id,"Relay Padam");
    }
    else{
      String balas;
      balas="Maaf, perintahnya salah. Coba kirim RELAY ON atau RELAY OFF.";
      robot.sendMessage(pesan.sender.id,balas);
    }
  }

}