Tired of ads? Enjoy an ad-free experience by signing up.
Kevin Lee · · 5 min read

What I learned from building a chatbot without a framework (part 1/2)

Photo credit: Robin Zebrowski

Photo credit: Robin Zebrowski

There is tremendous learning value in interfacing a bot with a bot API directly, without going through an external bot building framework.

To provide some context, the chatbot I built sends the user daily Twitter trends. It is called TwTrendsBot and is available on Telegram. You don’t need Twitter to use it. If you do have a Twitter account, it serves as a supplement to your Twitter experience, because the trends it sends you are country-specific.

Each platform allows different kinds of interactions

Things are simple when the chatbot and the user can only communicate in plaintext. However, different chat platforms like Facebook Messenger, Kik or Telegram provide different features and interactions that change the user experience substantially.

The best way to learn about what’s possible is to try their bot API directly, without going through an external framework or library.

For example, Telegram has a unique inline query feature, where the user can simply type “@bot_name ” from any chat to get some results. Therefore, the user does not always have to start a private chat with the bot in order to benefit from it.

Once the query is submitted, the bot can process it and generate a list of results, which can be formatted in a variety of ways. When the user selects a result, the message will be sent to the chat. For performance reasons, lazy loading and caching are supported by Telegram.

A sample list of inline query results

A sample list of inline query results

As I was finishing my bot, I realized that it was not enough to send the user a list of Twitter trends. After all, the user may want to see tweets related to a certain trending topic, and one way to do that is to direct the user to Twitter via a specific link.

Thankfully, I discovered that the Telegram API supports custom hyperlinks with HTML tags, so I could keep the message really succinct! The user can simply tap on an individual trend to open up Twitter and view the tweets related to it.

A list of trends with selectable hyperlinks

Service messages are useful

I handled the different ways in which the user could stop my bot

Frameworks can be unexpectedly complex

Conclusion

Stay ahead in Asia’s tech landscape

You've reached your 2 free content limit for the month. Sign up for free to read the full story.

🏄 For casual readers / 👶 Free

Basic

US$0

Free forever

Get instant access to this article and more every month

0 premium content

Unlimited news briefs

5

5 articles

Ad-free reading experience

Just US$0 per day

⌛Sign up in 20s. No payment details needed.

📖 For learners / 👍 Starter

Lite

US$4.92/month

Billed annually at US$59/year

Get instant access to this article and more every month

4

4 premium content

Unlimited news briefs & articles

Ad-free reading experience

Just US$0.17 per day

Cancel anytime

Our subscriber community includes professionals from these companies:

Stay updated on the go with our mobile app.

Get latest insights with smoother, more personalized experience through TIA mobile app.

Community Writer

Kevin Lee

I'm a software engineer and entrepreneur, who is passionate about design and emergent technologies.