#include <ESP8266WiFi.h>
#include <UniversalTelegramBot.h>

// WiFi settings
const char* ssid = "Dua Cakra";
const char* password = "corazon777";

// Telegram settings
const char* telegramToken = "5992106882:AAFONXAkytzl5uF8-FDEai47tpvhV5M7g5Y";
int telegramChatId = 1858267482;

// Initialize WiFi and Telegram objects
WiFiClientSecure client;
UniversalTelegramBot bot(telegramToken, client);

void setup() {
  // Connect to WiFi
    Serial.begin(115200);
      WiFi.begin(ssid, password);
        Serial.println("Connecting to WiFi...");
          while (WiFi.status() != WL_CONNECTED) {
              delay(1000);
                  Serial.println("Connecting...");
                    }
                      Serial.println("WiFi connected");

                        // Print local IP address
                          Serial.println(WiFi.localIP());
                          }

                            // Print local IP address
                              Serial.println(WiFi.
                              localIP());
                              }

                              void loop() {
                                // Check for incoming messages
                                  int numNewMessages = bot.getUpdates(bot.last_message_received + 1);

                                    // Process each incoming message
                                      for (int i = 0; i < numNewMessages; i++) {
                                          String chat_id = String(bot.messages[i].chat_id);
                                              String text = bot.messages[i].text;

                                                  // Send a reply to the message
                                                      bot.sendMessage(chat_id, "Received your message: " + text);
                                                        }

                                                          // Send a message to the chat
                                                            bot.sendMessage(telegramChatId, "Hello from Arduino!");
                                                              
                                                                // Wait for 5 seconds before sending another message
                                                                  delay(5000);
                                                                }
esp:0
esp:1
esp:2
esp:3
esp:4
esp:5
esp:6
esp:7
esp:9
esp:10
esp:18
esp:19
esp:20
esp:21
esp:RST
esp:3V3
esp:NC1
esp:GND
esp:8.1
esp:8.2
esp:NC2
esp:NC3
esp:NC4
esp:NC5
esp:NC6
esp:5V
esp:EN
esp:BAT+
led1:A
led1:C
btn1:1.l
btn1:2.l
btn1:1.r
btn1:2.r