Home Applications Telegram adapter

Telegram adapter

This application is not supported by InterSystems Corporation. Please be notified that you use it at your own risk.
5
1 reviews
0
Awards
414
Views
39
IPM installs
0
3
Details
Releases (5)
Reviews (1)
Issues
Articles (2)
Dependencies (2)
Dependants (2)
Telegram adapter for InterSystems IRIS

What's new in this version

  • fixed maxlen for Filename

Telegram adapter for InterSystems IRIS

The IRIS Telegram Adapter allows you to easily connect to the Telegram API in your interoperability solution.

You can use the Telegram Adapter to accomplish simple tasks, such as sending notifications from IRIS to Telegram chats, or create more complex scenarios using one or more Telegram bots.

The Telegram Adapter includes:

  • Telegram package - main classes
  • Web application /tg for webhooks

Using the Telegram adapter

Outbound Adapter

The Telegram API provides a set of methods https://core.telegram.org/bots/api#available-methods that allow you to send various types of messages or perform other actions to manage chats.

To call any of these methods, follow these steps:

  1. Install the Telegram Adapter.
  2. Add a business-operation Telegram.BusinessOperation to your Production
  3. Specify the required parameters for connecting to the telegram API in the Connection Settings block:
    • Server (usually api.telegram.org)
    • Token
    • SSL Configuration
  4. Create a message object of the Telegram.Request class, specify its properties, and send to the Telegram.BusinessOperation business operation

Example 1

    Set msg = ##class(Telegram.Request).%New()
    Set msg.Method = "sendMessage"
    Set msg.Data = {
        "chat_id" : (сhatId),
        "text": "Some text here"
    }
    Return ..SendRequestAsync("Telegram.BusinessOperation", msg)

Property Method - The Telegram API Method
Property Data – JSON object, the fields of which correspond to those described in the documentation https://core.telegram.org/bots/api#available-methods.

If the Telegram API method involves sending files/photos/videos/audio, then you should specify the full file name in the corresponding field, and at the same time add this file name to the Files collection. The specified file must exist and be readable.

Example 2

    Set msg = ##class(Telegram.Request).%New()
    Set msg.Method = "sendPhoto"
    Set msg.Data = {
            "chat_id": (chatId),
            "photo": "/my/photo/1.jpg"
       }
    Do msg.Files.Insert("/my/photo/1.jpg")
    Return ..SendRequestAsync("Telegram.BusinessOperation", msg)

The data received from the Telegram API is available in the response object.

Example 3

    Set msg = ##class(Telegram.Request).%New()
    Set msg.Method = "getMe"
    Set tSC = ..SendRequestSync("Telegram.BusinessOperation", msg, .response)
    $$$TRACE(response.Data.%ToJSON())

You will found more examples in the Demo (https://openexchange.intersystems.com/package/telegram-adapter-demo)

Inbound Adapter

Allows you to receive data from telegram (messages written by other users in chats).

2 options are supported:

  • Webhook
  • Long polling (periodic polling) of the Telegram API to get updates

How to get a token

Use telegram bot @BotFather. Use the /newbot command to create a new bot - you will receive a token (token example 110201543:AAHdqTcvCH1vGWJxfSeofSAs0K5PALDsaw). Read more here https://core.telegram.org/bots/features#botfather.

Demo Echo demo app

Now Echo demo app is in another package - telegram-adapter-demo (https://openexchange.intersystems.com/package/telegram-adapter-demo)

Made with
Install
zpm install telegram-adapter download archive
Version
1.1.220 Jun, 2023
Category
Integration
Works with
InterSystems IRIS
First published
30 Nov, 2022
Last checked by moderator
26 Nov, 2024Doesn't work