• Arduino
    • Sensor
    • program Arduino
  • Project
  • Produk
  • IOT
Jumat, Oktober 3, 2025
mikroavr.com
No Result
View All Result
  • Login
  • Arduino
    • Sensor
    • program Arduino
  • Project
  • Produk
  • IOT
  • Arduino
    • Sensor
    • program Arduino
  • Project
  • Produk
  • IOT
No Result
View All Result
mikroavr
No Result
View All Result
Home IOT

NodeMCU Telegram Bot – How to Limit the number of User that can access our telegram Bot

Jimmi Sitepu by Jimmi Sitepu
Maret 15, 2018
0 0
0
limit user telegram bot

limit user telegram bot

1
SHARES
6.5k
VIEWS
Share on FacebookShare on Twitter

NodeMcu

NodeMCU is open source devices and software. NodeMCU is good platform to create IOT project because has wifi Module, large memory flash, and more I/O. Wifi module on nodeMCU makes us able to access internet connection. this point is avantage to create IOT project. This articel, we will show how to make telegram bot and access it with NodeMCU. How to create it?

NodeMCU Telegram Bot

We will try how to control led or other device with telegram bot. for example try send message “/ledon” to our telegram bot, so NodeMCU will receive our message, and led will on. No metter how far telegram user with NodeMCU device. We can control them.

READ ALSO

4G GSM Modul Arduino SIM7600 Cocok Untuk ESP32, STM32 atau Arduino Mega

Custome GPS Logger Arduino dengan Akeses Internet SIM7600 4G

But the problem is public user. Telegram Bot is public user. Every one can search our telegram bot or some one share our telegram bot to each other. so they can control our device too. is big problem. So how to limit user can access our telegram bot? let try together.

  1. Read before how to add board NodeMCU at Arduino IDE
  2. Download telegram Library

Check account Telegram

Before we limit user who can access our telegram bot, let try check our account direct with telegram bot, code below,

/*******************************************************************
 *  this is a basic example how to program a Telegram Bot          *
 *  using TelegramBOT library on ESP8266                           *
 *                                                                 *
 *  Open a conversation with the bot, you can command via Telegram *
 *  a led from ESP8266 GPIO                                        *
 *  https://web.telegram.org/#/im?p=@FlashledBot_bot               *
 *                                                                 *
 *  written by Giancarlo Bacchio                                   *
 *******************************************************************/
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include <ESP8266TelegramBOT.h>

const char* ssid = "ssid_name";
const char* password = "pass_wifi";
WiFiServer server(80);


// Initialize Telegram BOT

#define BOTtoken "your_token_bot"  //token of FlashledBOT
#define BOTname "botName"
#define BOTusername "BotUsername"

TelegramBOT bot(BOTtoken, BOTname, BOTusername);
  

int Bot_mtbs = 1000; //mean time between scan messages
long Bot_lasttime;   //last time messages' scan has been done
bool Start = false;

/********************************************
 * EchoMessages - function to Echo messages *
 ********************************************/void Bot_ExecMessages() {
  for (int i = 1; i < bot.message[0][0].toInt() + 1; i++) { 
  bot.message[i][5]=bot.message[i][5].substring(1,bot.message[i][5].length()); 
if (bot.message[i][5] == "me") { 
bot.sendMessage(bot.message[i][4], bot.message[i][0], ""); 
bot.sendMessage(bot.message[i][4], bot.message[i][1], ""); 
bot.sendMessage(bot.message[i][4], bot.message[i][2], ""); 
bot.sendMessage(bot.message[i][4], bot.message[i][3], ""); 
bot.sendMessage(bot.message[i][4], bot.message[i][4], ""); 
bot.sendMessage(bot.message[i][4], bot.message[i][5], ""); 
} 
} 
bot.message[0][0] = ""; // All messages have been replied - reset new messages 
} 
void setup() { 
Serial.begin(115200); 
delay(3000); // attempt to connect to Wifi network: 
Serial.print("Connecting Wifi: "); 
Serial.println(ssid); 
WiFi.begin(ssid,password); 
while (WiFi.status() != WL_CONNECTED) { 
delay(500); 
Serial.print("."); 
} 
Serial.println(""); 
Serial.println("WiFi connected"); 
Serial.print("http://"); 
Serial.print(WiFi.localIP()); 
bot.begin(); // launch Bot functionalities 
} 
void loop() { 
if (millis() > Bot_lasttime + Bot_mtbs)  {
    bot.getUpdates(bot.message[0][1]);   // launch API GetUpdates up to xxx message
    Bot_ExecMessages();   // reply to message with Echo
    Bot_lasttime = millis();
  }
}

 

after we upload code to nodeMCU, try send message to your telegram bot with “/me”. Your telegram bot will replay with your Telegram ID, name, last name and message. Check video below.

this video will show what is our ID. our ID is 11935626. now lets try how to limit user access the NodeMCU telegram bot.

change code like this

/*******************************************************************
 *  this is a basic example how to program a Telegram Bot          *
 *  using TelegramBOT library on ESP8266                           *
 *                                                                 *
 *  Open a conversation with the bot, you can command via Telegram *
 *  a led from ESP8266 GPIO                                        *
 *  https://web.telegram.org/#/im?p=@FlashledBot_bot               *
 *                                                                 *
 *  written by Giancarlo Bacchio                                   *
 *******************************************************************/
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include <ESP8266TelegramBOT.h>


// Initialize Wifi connection to the router
//char ssid[] = "mikroavr.com";              // your network SSID (name)
//char pass[] = "jimmiKS@888";                              // your network key

const char* ssid = "mikroavr.com";
const char* password = "jimmiKS@888";
WiFiServer server(80);


// Initialize Telegram BOT

#define BOTtoken "your_token"  //token of FlashledBOT
#define BOTname "xxxx"
#define BOTusername "xxxx_bot"

TelegramBOT bot(BOTtoken, BOTname, BOTusername);
  

int Bot_mtbs = 1000; //mean time between scan messages
long Bot_lasttime;   //last time messages' scan has been done
bool Start = false;

/********************************************
 * EchoMessages - function to Echo messages *
 ********************************************/void Bot_ExecMessages() {
  for (int i = 1; i < bot.message[0][0].toInt() + 1; i++) { 
bot.message[i][5]=bot.message[i][5].substring(1,bot.message[i][5].length()); 
if (bot.message[i][5] == "ledon") { 
if ( bot.message[i][1] == "119353626"){ 
digitalWrite(LED_BUILTIN, LOW); // turn the LED on (HIGH is the voltage level) bot.sendMessage(bot.message[i][4], "Led is ON by Jimmi", ""); 
} else{ 
bot.sendMessage(bot.message[i][4], "Unknown User", ""); 
} 
} 
if (bot.message[i][5] == "ledoff") { 
if ( bot.message[i][1] == "119353626"){ 
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level) bot.sendMessage(bot.message[i][4], "Led is Off by Jimmi", ""); 
} 
else { 
bot.sendMessage(bot.message[i][4], "Unknown User", ""); 
} 
} 
if (bot.message[i][5] == "start") { 
String wellcome = "Wellcome from mikroavr_bot, your personal Bot on alarm realtime notification"; 
String wellcome1 = "/ledon : to switch the Led ON"; 
String wellcome2 = "/ledoff : to switch the Led OFF"; 
String wellcome3 = "/sensor : status all sensor"; 
if ( bot.message[i][1] == "119353626"){ 
bot.sendMessage(bot.message[i][4], wellcome, ""); 
bot.sendMessage(bot.message[i][4], wellcome1, ""); 
bot.sendMessage(bot.message[i][4], wellcome2, ""); 
bot.sendMessage(bot.message[i][4], wellcome3, ""); 
Start = true; } 
else { 
bot.sendMessage(bot.message[i][4], "unkwon user", ""); 
} 
} 
} 
bot.message[0][0] = ""; // All messages have been replied - reset new messages 
} 
void setup() { 
Serial.begin(115200); 
(3000); // attempt to connect to Wifi network: 
Serial.print("Connecting Wifi: "); 
Serial.println(ssid); 
WiFi.begin(ssid,password); 
while (WiFi.status() != WL_CONNECTED) {
delay(500); 
Serial.print("."); 
} 
Serial.println(""); 
Serial.println("WiFi connected"); 
Serial.print("http://"); 
Serial.print(WiFi.localIP()); 
bot.begin(); // launch Bot functionalities 
pinMode(LED_BUILTIN, OUTPUT); // initialize digital pin 2 as an output. 
}
void loop() { 
if (millis() > Bot_lasttime + Bot_mtbs)  {
bot.getUpdates(bot.message[0][1]);   // launch API GetUpdates up to xxx message
    Bot_ExecMessages();   // reply to message with Echo
    Bot_lasttime = millis();
  }
}

now we can’t control LED with message “/ledon, because the id is not same. we can’t check below

nodeMCU telegram botnodeMCU telegram bot

I hope this articel can help us to create nodeMCU telegram bot with safe user from unknow user

download nodeMCU program here

https://github.com/jimmisitepu88/mikroavr.com/tree/master/NodeMCU%20Telegram%20Bot

Thanks

Tags: nodemcutelegram bot
ShareTweet
Previous Post

Fungsi Rangkaian Optocoupler Sebagai Switch,Cara kerja dan Contoh Aplikasi nya

Next Post

Alat Penambah Daya Listrik PLN Dirumah, Murah dan Berkualitas

Jimmi Sitepu

Jimmi Sitepu

Hobbyist Embedded System, Robotic, IOT and write all about them. So we have nice quote "Learning and Sharing"

Related Posts

4G GSM Modul Arduino SIM7600 Cocok Untuk ESP32, STM32 atau Arduino Mega
Arduino

4G GSM Modul Arduino SIM7600 Cocok Untuk ESP32, STM32 atau Arduino Mega

Juni 13, 2022
Custome GPS Logger Arduino dengan Akeses Internet SIM7600 4G
IOT

Custome GPS Logger Arduino dengan Akeses Internet SIM7600 4G

April 14, 2022
Tutorial Menggunakan Weather Station DFRobot SEN0186 dengan Arduino ESP32
Arduino

Tutorial Menggunakan Weather Station DFRobot SEN0186 dengan Arduino ESP32

Maret 9, 2022
saklar sms arduino sim800
Arduino

Saklar SMS Arduino dengan SIM800 Untuk Kontrol Jarak Jauh, Download Program nya

Februari 23, 2022
Arduino

Sensor Tekanan Air Dan Udara Dengan Arduino

Desember 20, 2020
Enkripsi Data Lora pada Modul ESP32 Lora
Arduino

Enkripsi Data Lora pada Modul ESP32 Lora

Maret 1, 2020
Next Post
Alat Penambah Daya Listrik PLN Dirumah, Murah dan Berkualitas

Alat Penambah Daya Listrik PLN Dirumah, Murah dan Berkualitas

fungsi millis

Fungsi Millis Pada Arduino, Contoh Program dan Pengertiannya

Please login to join discussion

Tulisan Terbaru

sensor URM14 Arduino

Membaca Sensor URM14 RS485 dengan ESP32 Arduino

Juli 7, 2022
4G GSM Modul Arduino SIM7600 Cocok Untuk ESP32, STM32 atau Arduino Mega

4G GSM Modul Arduino SIM7600 Cocok Untuk ESP32, STM32 atau Arduino Mega

Juni 13, 2022
Mendapatkan Waktu Akurat dengan NTP GPS

Mendapatkan Waktu Akurat dengan NTP GPS

Mei 8, 2022
Custome GPS Logger Arduino dengan Akeses Internet SIM7600 4G

Custome GPS Logger Arduino dengan Akeses Internet SIM7600 4G

April 14, 2022
Tutorial Menggunakan Weather Station DFRobot SEN0186 dengan Arduino ESP32

Tutorial Menggunakan Weather Station DFRobot SEN0186 dengan Arduino ESP32

Maret 9, 2022
ethernet arduino

Arduino Ethernet Tutorial, Project dengan Arduino Uno dan Mega

Februari 24, 2022

Browse by Category

  • Arduino
  • Ebook
  • ESP32
  • IOT
  • jasa
  • Komponen
  • PCB
  • Produk
  • program Arduino
  • Project
  • Rangkaian
  • Sensor
  • Tips
  • Uncategorized

Recent News

sensor URM14 Arduino

Membaca Sensor URM14 RS485 dengan ESP32 Arduino

Juli 7, 2022
4G GSM Modul Arduino SIM7600 Cocok Untuk ESP32, STM32 atau Arduino Mega

4G GSM Modul Arduino SIM7600 Cocok Untuk ESP32, STM32 atau Arduino Mega

Juni 13, 2022
  • About US
  • Blog
  • MIKROAVR

© 2020 mikroavr.com - Learning and sharing.

Welcome Back!

Sign In with Google
OR

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In

Add New Playlist

No Result
View All Result
  • About US
  • Blog
  • MIKROAVR

© 2020 mikroavr.com - Learning and sharing.