/TelegramBot

Telegram Bot framework for Squeak/Smalltalk

Primary LanguageSmalltalk

TelegramBot

Actions Status Coverage Status

A Telegram Bot framework for Squeak/Smalltalk. Supports receiving, sending, and editing of multi-media messages such as photos, formatted text, and files. Provides a robust server mode to keep bot servers running in the background of your Smalltalk image. Basic support for group chats and channel posts.

Used by the TelegramSmalltalkBot.

Installation

Install the latest Trunk updates in your image before installing the repository:

... using Metacello

Metacello new
	baseline: 'TelegramBot';
	githubUser: 'LinqLover' project: 'TelegramBot' path: 'src';
	load.

... as a dependency in your Metacello baseline

spec baseline: 'TelegramBot' with: [
	spec repository: 'github://LinqLover/TelegramBot/src'].

Usage

For a simple example, see the class TBEchoBot from the system category TelegramBot-Examples. To run the bot, you first need to create a bot with the help of @BotFather. After that, you can run this or any other bot by evaluating the following in a workspace:

bot := TBEchoBot withToken: '<your_bot_token>'.
bot spawnNewProcess.

You can also terminate the bot again by sending #terminate to it, or invoke it manually for one update cycle using the #doOneCycleNow message. For the full protocol, browse the message category update cycle on TelegramBot.

If you do not want that everyone from all over the world has access to your bot, you can define an allow-list of chat IDs and provide it via the TBTestBotChatIds global variable (experimental):

Smalltalk at: #TBTestBotChatIds put: #(<your_chat_id_integer>).

You can find out your own chat ID by browsing the sessions object of your running bot instance using an object explorer, or by inspecting the result of bot peekUpdates after sending a message to the bot.

Documentation

... is still to be done. :-) In a nutshell: When building your bot, subclass from TelegramBot. Relevant hooks to override are defined in the update handling protocol and you can use the messages from the message sending protocol to send replies to users.

To learn more about the possibilites of Telegram bots, take a look at the official documentation of the Telegram Bot API.

Disclaimer: Since this framework is still under development, breaking design changes are possible. Make sure to browse all open issues and to watch the repository when you start working with this framework.

Development

This framework is still under development. Nevertheless, all kinds of contributions are already very welcome! Please submit as much bug reports, new feature proposals, or even pull requests as possible. :-)

Version control is run using Squot.

Nice idea, but it this framework actually used by any project?

TelegramBot was mainly developed to build TelegramSmalltalkBot, a bot which allows you to access a remote Squeak and execute Smalltalk expressions in it:

@SqueakSmalltalkBot

However, this framework has not been abstracted from TelegramSmalltalkBot for nothing, so it should be definitively usable for other bots as well. If you have developed another bot using this framework, please feel free to create a PR that references your project!