Releases: vasilsaroka/TelegramBotAPI
TelegramBotAPI - AI agents are not there yet?
Release Notes
In year 2024, artificial intelligence (AI) not only continued to fuel innovation in various fields of economy, healthcare, science and education, but also itself underwent an significant transformation. In brief, we have seen a dramatic going down of prices due to increased energy efficiency and competition at the market and flourishing in features due to introduction of the multi-modal and reasoning models. Yet, commercial products and technical infrastructure growing around the base service providers, according to experts, have failed in delivering AI agents as the majority envisaged them. One of the reasons is a lack of sharp focus and specific problem approach. While this general conclusion is arguable, it definitely contains a grain of truth. In other words, there is a lot of room for improvement and further trial in delivering meaningful AI-based services. In TBpack Ltd., we believe we have managed to provide some meaningful assistance with our Telegram chatbots reinforced with AI by being focused on the areas we deal with, i.e. conference management, and problems we solve, i.e. conference agenda compilation and participants navigation. Therefore, we ready to share our tools wrapped as a new release of TelegramBotAPI package.
Telegram Bot API
In this version tagged v0.2.0, we have expanded the range of the accessible Telegram Bot API functions and updated the previously released functions to the Telegram Bot API 8.2 released on 1 Jan 2025. This package does not contain all possible functions but rather it contains all the functions that we have used in our TBpack Ltd. chatbots.
In order to implement all the functions, we had to develop and stick to certain basic principles of organization, that are useful to know for everyone who has intention to try this package for developing their unique products. Let us begin with reminding that Wolfram Language base principle in naming convention is to give all the built-in symbols explicit linguistic names reflecting their semantics, starting from the capital letter and capitalizing the letter of any new word used in the symbol name. This is very powerful and easy to grasp principle that gives Wolfram Language an advantage of clarity, readability and quick start, which later at an expert level can be reinforced by aliases making code concise, though less clear. In our case, clarity was our main objective, therefore we used "semantic" naming convention as a starting point. However, we noticed that quite often it comes at odds with functions from outside the Wolfram Language without an explicit renaming of them. Keeping in mind clarity and coherence that are to be maintained across several services, we deemed the renaming as not appropriate and dared to amend the Wolfram Language naming conventions in those cases, where we wanted to keep the original "semantics" given to the services by their providers. These tweaks in symbol naming conventions are detailed below.
First of all, to separate TelegramBotAPI functions from built-in Wolfram Language functions we start them from lowercase letters and capitalize the letters of any new word in the name of the function. This allows to avoid conflicts between such built-in functions as SendMessage
and TelegramBotAPI functions as sendMessage
.
However, all the options of the TelegramBotAPI functions follow the naming convention of Wolfram Language. We hold this convention because it seems to be not introducing confusion, at least for work of the Wolfram Kernel. For example, the commonly used built-in Text
function of Wolfram Language "overlaps" with an option Text
of our answerCallbackQuery
function. The usage message returned for the Text
symbol will contain TelegramBotAPI usage message that overshadows the usage message of the Text
function of the Wolfram Language. However, when used as a function, say in Graphics[{Text["Hello!",{0,0}]}]
, the performance of the function is standard for the Wolfram Language. This is because option symbols are free of any definitions and protected from assigning to them any values which allows the same symbol to operate independently in two separate universes: a space of functions and a space of options.
Along with Telegram Bot API functions, the TelegramBotAPI package contains some custom functions, which are meant to facilitate bot development. Since these functions do not belong to the official Telegram Bot API, they follow the native Wolfram Language naming convention, e.g. MessageQ[...]
.
The standard Wolfram Language has two systems storing and retrieving basic information about symbols, i.e. functions, options etc.: Help and Documentation. The Help is represented by built-in tags attached as usage messages to every symbol. These usage messages are usually concise and only suitable for expert to recover some knowledge about this or that function. On the other hand, the Documentation center is a complex and comprehensive system that includes full range of options and supplemented by interactive examples. As such, it is targeting a fast learning of newcomers. The TelegramBotAPI package contains only Help, but we made an effort to make each usage message useful not only for experts but also for beginners. This hopefully was achieved by listing of all the options for each of the function and provided url links to the official Telegram Bot API documentation. We believe it is a trade off between a complex Documentation center and limited Help.
Open AI API
The modern bots are unimaginable without large language models (LLMs), though in general bots can operate and perform many useful tasks even without LLMs. Therefore, in this release, we supplemented TelegramBotAPI with a subpackage providing access to the OpenAI API. This subpackage is realized as a separate context "TelegramBotAPI`OpenAI`" that is loaded together with TelegramBotAPI and must facilitate development of human-like chatbots.
The functions of this subpackage follow naming convention of the TelegramBotAPI package, but all the options are chosen to be provided as strings that follow option names exactly as they are described in official OpenAI API documentation available on web. We hope this will allow one to quickly make a clear relation between options and their usage. For example, chatCompletion[]
function of "TelegramBotAPI`OpenAI`" context has an option "frequency_penalty" that can be set as chatCompletion[message,model,"frequency_penalty"->1]
. Specifying options as strings means they do not have associated symbols for them and, therefore, no usage message tags. However the usage message of the related function, i.e. chatCompletion
, lists all the available options and has a link to the official web page in OpenAI API documentation.
New players on the stage - xAI API
At the moment, the competition between LLMs providers is sky-high. Therefore, it would be bias to advertise one provider such as OpenAI even if it is considered kind of the best on the market. Taking this into account, we extended TelegramBotAPI with xAI API. This is supposed to give developer a freedom of choice between OpenAI and xAI LLMs. xAI API has appeared on the market just recently — 4th November 2024 — and to acquire audience by reverting part of the OpenAI customers to their service, they thoughtfully made the migration to xAI API as hustle-free as possible. Namely, they fully copied the structure and names of the OpenAI API functions so that xAI API could be accessed using an official Python client of OpenAI by changing only the name of requested model and the access end point. Technically, this means that xAI API can be accessed in TelegramBotAPI via "TelegramBotAPI`OpenAI`" context and chatCompletion
function. We, however, decided to put xAI API functions into a separate context "TelegramBotAPI`xAI`", because, since release of xAI API in November 2024, OpenAI deployed API for their new reasoning models (o1-preview and o1-mini) and, therefore, introduced new options for their API, which are not relevant for xAI API. In order to make difference between chatCompletion
functions in the OpenAI and xAI contexts, we supplemented the function name with a postfix "Xai". Thus, the chatCompletion[]
function in "TelegramBotAPI`xAI`" context became chatCompletionXai[]
. All options in this context are supposed to follow the same string-type convention as described for "TelegramBotAPI`OpenAI`" context.
ElevenLabs API
Despite entering a multi-modal era that allows neural networks to work with text, images, video and audio, LLMs are still mostly about text. The specialized single-mode models are much better for professional tasks. In particular, professional text to speech conversion requires variety of voices (male and female ones), intonations, emotional expressions, and sound effects (such as environment and background, accent, speaker age and etc.). That is why we added ElevenLabs API functions, specialized on work with audio, as a subpackage of TelegramBotAPI package. In this subpackage, functions follow the same naming convention as in xAI context, i.e. they carry a postfix "XI". For example, textToSpeechXI[]
is the one to be used for converting...
TelegramBotAPI - The rise of AI
Chatbots were originally designed to mimic human interactions through text. Over time, they evolved to handle images, voice, and video, transforming into powerful interfaces for sophisticated programs and software. With the recent rise of Large Language Models within Artificial Intelligence (AI), chatbots have entered a new dimension, becoming integral to numerous applications.
One of the most natural environments for chatbots is messenger platforms. Among these, Telegram stands out with its rich features and advanced functionality. Telegram offers a variety of interface elements to create a fully interactive experience for bot users. Additionally, the clear documentation for the Telegram Bot API makes development and maintenance straightforward.
The Bot API is an HTTP-based interface that can be accessed and integrated with various programming languages, bringing the full capabilities of these languages to the Telegram platform. To streamline this process, structured layers known as frameworks or API clients are commonly used.
Despite the unique capabilities of Wolfram Language, suitable frameworks have been limited. An older client by Guillermo Hernández and a newer one by Kirill Belov are available on GitHub. We aim to provide our alternative to fully harness the power of symbolic computation in the age of AI.
We are excited to release our Telegram Bot API package for Wolfram Language, a framework we have been developing and rigorously testing since March 2021. This package aims to unlock the potential of symbolic computations and seamless integration with Telegram, paving the way for innovative three-way exchange that involves user, provider and humanized software bot.