Skip to content

Telegram Bot

Paolo Grasso edited this page Sep 3, 2020 · 1 revision

General info

The bot is based on the python-telegram-bot library available for Python 3. The version used in this project is 11.1.0 so be sure to read the correct documentation since the library has undergone major changes between versions 11 and 12.

The bot uses standard command handlers in order to reply to users.

It also features MQTT publisher and subscriber to send irrigation commands and listen to irrigation tasks.

Execution

When executed, the bot should:

  • Ask the catalog the token for the actual Telegram Bot.
  • Activate the various commands with handlers.
  • Start a thread with an MQTT subscriber which listens to messages from irrigators.

Commands

/start The first command which a user sends when he starts a conversation to the bot. The bot replies with a welcome message, looks for the chat_id of the conversation and registers it on the static catalog.

/help The bot replies with the list of possible commands.

/status [id] The bot asks the catalog the list of all gardens, plants and active sensors. It sends back to the user information about owned gardens. If id word parameter is provided, the information also contains gardenIDs, plantIDs and devIDs (useful for debug).

/values <plantID> The bot asks the ThingSpeak adaptor current values of environmental parameters for the provided plant and it sends back to the user a short summary.

/irrigate The bot sends an irrigation message (via an MQTT publisher) to the plants associated to the user.

Notifications about irrigations

The always active MQTT subscriber listens to irrigation messages sent by irrigators. When it receives one, it sends a notification to the users associated with the plant which is currently irrigated. The messages are sent via a REST request using the SendMessage method of Telegram Bot API.

Clone this wiki locally