Telegram Bot — The New User Interface

Parsers for HTML and Markdown are readily available to format your messages if needed.

There is also support for Emoticons .

In order to obtain the correct chatId, you can use the /getMe method with your bot's auth token like this: https://api.

telegram.

org/bot<token>/getMeTalk to your botNow to the hard(er) part — implementing commands.

First you want to implement suggested basic commands /start, /help and /settings (if applicable).

Next are your individual commands that provide your bot functionality.

For me, those are commands the users may execute to configure the application.

In my case there is a very limited set of configuration values so I can make use of the inline keyboard to display pre-defined options to the user.

Let’s look at it in code.

Here for example, the /set-user command would provide three options upon execution.

The user may simply tap on one of them which would result in a callback_query event on the server side.

Depending on the callback_data provided, you can again display further options and thus guide the user through the setup process.

Here is an example:bot.

onText(//set_user/, (msg) => { bot.

sendMessage(msg.

chat.

id, 'Got it, please select an option below:', { reply_markup: { inline_keyboard: [[ { text: 'Id Number', callback_data: 'USER_ID_NUMBER' }, { text: 'Id Type', callback_data: 'USER_ID_TYPE' }, { text: 'Date Of Birth', callback_data: 'USER_DOB' } ]] } });});bot.

on("callback_query", (callbackQuery) => { const message = callbackQuery.

message; switch (callbackQuery.

data) { case 'USER_DOB': bot.

sendMessage(message.

chat.

id, 'Got it, please type DATE OF BIRTH in the following format: DD/MM/YYYY'); break; default: bot.

sendMessage(message.

chat.

id, 'I am sorry, this action is not implemented!'); break; }});In my opinion this setup process is very comprehensible and my clients felt really comfortable using it.

This way, they feel a close interaction with the software and I gotta say response times are incredibly fast.

Security and usabilityObviously, for security reasons, you should consider access control by username (or chat id), and Turn groups off in the bot settings to forbid users to add your bot to other groups.

You can also use the /setjoingroups command for that as shown in the image below.

Once you are done, don’t forget to actually provide a list of your commands to the BotFather.

You can do that using /setcommands in your conversation with BotFather.

This is very helpful for the end user, because he will then get a list of supported commands when he enters a '/' in the chat and can simply tap on one of them.

I know there really is no rocket science about this, but I hope I was able to communicate my general idea.

It is just something to keep in mind when designing your next application.

I really felt that communication with the software using the bot felt natural to the users.

There are multiple integration options besides notifications, e.

g.

website login through Telegram and even accepting payments.

Please leave a comment if you have any further questions or suggestions.

Leave a like if you found this article helpful.

Bonus section — Telegram Payment APITo enable even more advanced use-cases, Telegram bots can now also accept payments for goods and services (details see here).

They are then called Merchant bots.

I played around with the Payment API using the Stripe test server.

I admit, it really is a seamless integration for the user, and I believe it will be huge in the future.

Unfortunately, none of the currently integrated payment providers offer their services in Cyprus so it is still waiting time for me.

Originally published at https://thehooraymedia.

com on April 13, 2019.

.

. More details

Leave a Reply