Online tech learner logo
Online Tech Learner
  • Please enable News ticker from the theme option Panel to display Post

MQTT Telegram , a Coreflux Flux Asset | by Paulo Mota | Coreflux Blog

MQTT Telegram , a Coreflux Flux Asset | by Paulo Mota | Coreflux Blog

[ad_1]

Coreflux’s MQTT Telegram, as the name implies, is an asset focused on creating a Telegram bot for your MQTT pipeline, provided by our MQTT Broker. This asset places great power in your hands (which, as you may remember from Philosophy classes or more recently from Spider-Man, brings great responsibility).

This bot’s prime directive is to Inform and Control. Specifically, to have a set of topics with configured commands, having other functions such as sharing content provided by other assets like the ONVIF camera Flux Asset.

Telegram is a multi-purpose instant messaging platform, which also allows file-sharing. In the present context of the impact of a Coreflux Telegram Asset, these characteristics combine to provide great versatility, as they can be combined with other assets seamlessly.

Before you install the Telegram Flux Asset, you need to have a bot base prepared on Telegram. For this, you have to create that base on Telegram’s own main bot, called BotFather.

To do so, open your Telegram application. This can be done either on your mobile or on your computer. Note however, that you will receive a long hash key that you will need to either copy + paste or transcribe manually.

Once you have the Telegram application open, search for BotFather (beware of fakes, the real one has a blue checkmark icon in front of the name, confirming its authenticity), and initiate a conversation. If you are shy, don’t worry, it’s a bot, not a real person.

You will be greeted with an initial message. Press the START button, and the following menu will appear:

Type the /newbot command. In response, you will be prompted to:

  • Write the bot’s name, which must end in “bot” (this can be any name you’d like) [Ex.: MargeBot]
  • Write the bot’s username, which must end in “bot”, and must be unique (it may be troublesome to find common identifiers not yet used, but keep trying) [Ex.: Marge13579bot]

Next, give the newly created bot some permissions.Type the /mybots command. Choose the ‘Bot Settings’ option, followed by ‘Channel Admin Rights’, and turn on “Publish in the Channel” privileges.

  • Once you press “Install”, you will be presented with the asset configuration window:
  • Configure your MQTT Broker address and port to match the settings you are using (the corresponding broker should be running when your start the Telegram asset).
  • On the ‘Telegram API Key’ textbox, write or paste the key that you received from Telegram’s BotFather.
  • After installation, the instance window for this asset installation will display the “Standby” status
  • For proper functioning the asset must be configured (see chapter 5).
  • To begin execution of the MQTT Telegram Flux Asset, press the Play button, and if successful, the instance status will change to “Running”.
  • If for some reason the inputted configuration fails to execute (or permission to run is not confirmed by the system), the asset will try to enter a run state but return to a halted state when failing to do so, displaying an error popup (on the GUI Hub) or message (on the command-line Hub). If the asset is running, but you’re not seeing responses on Telegram, see chapter 7 for possible Troubleshooting.
  • Before the asset is actually usable, you will need to configure the topics you wish to work with. On Coreflux versions below 1.2.0, this will be done through the asset’s XML file. Navigate to Coreflux’s installation folder, and locate the appropriate asset folder within the “instances” folder.
  • Open it. The XML section to alter is the following (on chapter 5, below, you will find an extensive explanation of how to carry out this configuration properly).
  • Once the asset is properly configured, save the file and return to the Coreflux Hub window.

5.1. Types of Tags

  • isSimpleMessageToTelegram: Posts a message on Telegram, from a source published on a MQTT topic. This message can be either static or dynamic. When filling in the CommandData field of the tag’s configuration, take the following format as example: At {time} the Value is {value} . The elements within brackets write output the timestamp {time} and what is actually published on the topic {value}.
  • isSimpleMessageFromTelegram: Publishes a message on MQTT, from Telegram.
  • isCommandWriteFromTelegram: Publishes a command-type message on MQTT, from Telegram. Can be used to send TRUE or FALSE to specific I/O’s through the pipeline.
  • isSendImageFromFolder: Adopts the folder defined in the tag as a ‘hotfolder’, any PNG file dropped in there will be sent by the bot to the defined channel or group
  • isSendVideoFromFolder: Adopts the folder defined in the tag as a ‘hotfolder’, any MP4 file dropped in there will be sent by the bot to the defined channel or group
  • isSendDocumentFromFolder: Adopts the folder defined in the tag as a ‘hotfolder’, any TXT / DOCX file dropped in there will be sent by the bot to the defined channel or group

7.1. Telegram not responding

If the asset is properly configured, and the asset is running, but Telegram is not reacting at all to publications, Telegram’s API may have locked a message and is returning an Error 409 (indicating that there is already a different instance running).

To solve this, head to BotFather, type /mybots, choose the appropriate entry, and revoke the current API key. A new one will be generated, which you should update on the asset’s configuration. Restart the asset, and it should now be working properly once you send the /start command to the bot.

[ad_2]

Source link

administrator

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *