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:
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:
Telegram.BusinessOperation
to your Productionapi.telegram.org
)Telegram.Request
class, specify its properties, and send to the Telegram.BusinessOperation
business operationExample 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)
Allows you to receive data from telegram (messages written by other users in chats).
2 options are supported:
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.
Now Echo demo app is in another package - telegram-adapter-demo (https://openexchange.intersystems.com/package/telegram-adapter-demo)