All Projects → jordiprats → micropython-utelegram

jordiprats / micropython-utelegram

Licence: Apache-2.0 license
Telegram API wrapper for microPython

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to micropython-utelegram

ESP-Alerts-for-Android
Send Android Notifications to an ESP32 with OLED display
Stars: ✭ 42 (+2.44%)
Mutual labels:  esp32
PMserial
Arduino library for PM sensors with serial interface
Stars: ✭ 41 (+0%)
Mutual labels:  esp32
uPyCam
Take a photo with an ESP32-CAM running MicroPython
Stars: ✭ 97 (+136.59%)
Mutual labels:  esp32
antirobot aiogram
Телеграм бот для блокировки спама
Stars: ✭ 26 (-36.59%)
Mutual labels:  telegram-bot-api
forwardscoverbot
telegram bot that echoes any message you send it or modify to anonymize messages
Stars: ✭ 150 (+265.85%)
Mutual labels:  telegram-bot-api
pikascript
Ultralightweight Python engine that can run with 4KB of RAM and 32KB of Flash (such as STM32G030C8 and STM32F103C8), and is very easy to deploy and expand.
Stars: ✭ 855 (+1985.37%)
Mutual labels:  esp32
IMU-VR-Full-Body-Tracker
Inertial Measurement Unit (IMU) based full body tracker for Steam VR.
Stars: ✭ 46 (+12.2%)
Mutual labels:  esp32
esphome-flasher
Simple GUI tool to flash ESPs over USB
Stars: ✭ 619 (+1409.76%)
Mutual labels:  esp32
opcua-esp32
Embedded OPC UA Server on ESP32 based on open62541 stack
Stars: ✭ 82 (+100%)
Mutual labels:  esp32
RPi-TELEBOT
Python based Telegram bot to monitor and control the raspberry pi
Stars: ✭ 19 (-53.66%)
Mutual labels:  telegram-bot-api
ESP DoubleResetDetector
ESP_DoubleResetDetector is a library for the ESP32/ESP8266 Arduino platform to enable trigger configure mode by resetting twice.
Stars: ✭ 34 (-17.07%)
Mutual labels:  esp32
canairio sensorlib
Particle sensor manager for multiple sensors: Honeywell, Plantower, Panasonic, Sensirion, etc. This is sensors layer of CanAirIO project too.
Stars: ✭ 24 (-41.46%)
Mutual labels:  esp32
microhomie
MicroPython implementation of the Homie MQTT convention for IoT.
Stars: ✭ 72 (+75.61%)
Mutual labels:  esp32
ESP32BleAdvertise
Simple library for BLE advertise using ESP32 in Arduino
Stars: ✭ 39 (-4.88%)
Mutual labels:  esp32
nestronic
Nestronic Game Music Synthesizer Alarm Clock
Stars: ✭ 24 (-41.46%)
Mutual labels:  esp32
telegram-bot-framework
Python Telegram bot API framework
Stars: ✭ 19 (-53.66%)
Mutual labels:  telegram-bot-api
esp32-transpiler
Transpile Golang into Arduino code to use fully automated testing at your IoT projects.
Stars: ✭ 53 (+29.27%)
Mutual labels:  esp32
pong
Basic uptime monitoring system, with email alerts and/or push notifications
Stars: ✭ 94 (+129.27%)
Mutual labels:  telegram-bot-api
MQTT VPN
IP over MQTT for ESP controllers and Linux
Stars: ✭ 95 (+131.71%)
Mutual labels:  esp32
stack-chan
A JavaScript-driven M5Stack-embedded super-kawaii robot.
Stars: ✭ 242 (+490.24%)
Mutual labels:  esp32

micropython-utelegram

This library provides a microPython interface for for a subset of the Telegram Bot API. Have been tested on an ESP32 but should work just fine on an ESP8266

Your first bot

On the demo folder you will find an example bot.

First you'll need to create a new bot using the BotFather to get a token for your bot. Once you have it rename the config.py-demo and set the variables (WiFI SID/password and your bot token):

wifi_config = {
    'ssid':'DEMO',
    'password':'PASSW0RD'
}

utelegram_config = {
    'token': 'TOKEN'
}

If you have your ESP32 connected as /dev/ttyUSB0 you can use the upload.sh script to upload the bot code to your micropython enabled ESP32:

./upload.sh

Example bot code

Initialize bot

To create a new bot you just need to create a ubot object passing the token the BotFather have provided:

bot = utelegram.ubot(utelegram_config['token'])

Register handlers

Handlers will receive the raw message as a parameter:

def reply_ping(message):
    bot.send(message['message']['chat']['id'], 'pong')

Messages will be in the following format:

{
   "update_id":302445393,
   "message":{
      "message_id":1492,
      "from":{
         "id":123456789,
         "is_bot":False,
         "language_code":"en",
         "first_name":"Jordi"
      },
      "text":"/ping",
      "date":1599563930,
      "entities":[
         {
            "offset":0,
            "length":5,
            "type":"bot_command"
         }
      ],
      "chat":{
         "id":123456789,
         "type":"private",
         "first_name":"Jordi"
      }
   }
}

You can register handlers using the register method:

bot.register('/ping', reply_ping)

And optionally set a default handler for any other message:

bot.set_default_handler(get_message)

Reply to messages

Using the send function we can reply to messages, the parameters are:

  • chat ID: chat ID is the same as the user ID except for group chats
  • message: text to send

For example, we can use the incoming message to get the chat_id to reply to:

bot.send(message['message']['chat']['id'], 'pong')

Bot loop

We can either let the bot loop but itself to reply to messages:

bot.listen()

Or we can loop manually using the read_once() function:

bot.read_once()

Using this method you should add a sleep between each time we poll the Telegram API

Other examples

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].