Skip to content

Latest commit

 

History

History
70 lines (45 loc) · 4.73 KB

README.md

File metadata and controls

70 lines (45 loc) · 4.73 KB

Xatkit Telegram Platform

License Badge Wiki Badge

Receive and send messages from Telegram.

The Telegram platform is a concrete implementation of the ChatPlatform.

We rely on this Java-based wrapper of the Telegram API for Bots.

Providers

The Telegram platform defines the following providers:

Provider Type Context Parameters Description
ChatProvider Intent - chat.channel: the identifier of the channel that sent the message
- chat.username: the name of the user that sent the message
- chat.rawMessage: the raw message sent by the user (before NLP processing)
Receive messages from a communication channel and translate them into Xatkit-compatible intents (inherited from ChatPlatform)
TelegramIntentProvider Intent - chat.channel: the identifier of the channel (chatID in Telegram terminology) that sent the message
- chat.username: the name of the bot that sent the message
- chat.rawMessage: the raw message sent by the user (before NLP processing)
Receive messages from a Telegram chat and translate them into Xatkit-compatible intents

Actions

Action Parameters Return Return Type Description
Reply - message (String): the message to post as a reply
- buttons (List[String], Optional): a list of values to render as quick message buttons as part of a custom ReplyKeyboard
The posted message String Posts the provided message as a reply to a received message (inherited from ChatPlatform). If the buttons parameter is specified the chat window will also print quick message buttons to drive the conversation.

Options

The Telegram platform supports the following configuration options

Key Values Description Constraint
xatkit.telegram.token String The Telegram token used by Xatkit to interact with the Telegram API. You can get a token via the BotFather service Mandatory
xatkit.telegram.botusername String The username of your Telegram bot Mandatory
xatkit.telegram.botname String The name of your Telegram bot Optional
xatkit.telegram.ignore_fallback_on_group_channels Boolean Whether the bot should simply ignore messages it doesn't understand when in a group Optional

Using the Telegram platform

Check the BotTest sample bot included in the repo for an example of a bot using this platform. Make sure also to include this dependency to your pom

        <dependency>
            <groupId>com.xatkit</groupId>
            <artifactId>telegram-platform</artifactId>
            <version>1.0.0-SNAPSHOT</version>
        </dependency>

Tips

Bots that start the conversation

To be able to write to a telegram group or user, you need to know the chat ID of that group or user.

If the user starts a conversation, the channel ID will be stored in the context by the TelegramIntentProvider in the handle method (see String channel = message.getChatId().toString(););

But if you want the bot to start the conversation, you'll need to create a context with the proper chat id yourself.

StateContext contextTelegram = telegramPlatform.createSessionFromChannel(telegramChatId);
telegramPlatform.reply(contextTelegram, telegramMessage);

Format of the strings for the bot

You can use markdown to format the strings that you send to the bot. The string can also contain emojis. Add them using their emoji unicode value.