Bots & APIs: A Non-Programmer’s Journey

(Part 1)

The story

APIs (Application Programming Interface) expose functionality of complex technical systems to the world. Understanding APIs of different web applications can be challenging, especially for non-programmers. Having someone/something translating this complexity into a friendly and easy to understand interface could be a big help. APIs make life easier, however when the implementation starts, various challenges may lurk:

  • Deciding on the best programming language to use for a specific project
  • Understanding the best ways to obtain API keys, to securely store and transmit information to the server
  • Working with 3rd party libraries for parsing responses from API requests

Nowadays marketing is dependent on the interactions between various technologies, each using their own API. I’m very keen on understanding the magic of APIs and to explore the ways they could be used. Before embarking on this exciting journey, I knew that I needed a couple of essentials to help me get started:

  1. A great mentor, someone I like to call AngelNeer (an engineer with huge amount of patience).
  2. A great topic, something that you’d like to learn more about even when you are tired or keen to work on something else – “cats” is the topic that works for me in all these scenarios. I actually named the bot after one of my cats – Lana.
  3. A great deal of time, as with learning any new skill, you’ll need to invest time in making it happen. Tip: holidays might be a good time start understanding what’s going on under the hood of API.

Project description

Bots are simply Telegram accounts operated by software – not people – and they’ll often have AI features.

This project is about implementing a simple Telegram bot which can respond to different user queries. To chat with the bot, you could search on Telegram contacts for @FuzzyLanaBot. Be aware that this bot is currently running on my machine. The next step will be to deploy it onto online web app hosting platform.

LanaBot aims to include 3-4 key functionalities. For now, it’s able to respond to weather requests – this bot has only 200 lines of Python code and it has hard-coded 2 cities: my current city and my preferred holiday destination:

There’s also the option to get weather status from your exact location, if you’re willing to share your location with LanaBot:

Technologies and tools

  • As with cat food, APIs come in different flavours. For our project we used something that’s called REST API, both for managing the bot and for getting weather updates.
  • Telegram Bot API – “The Bot API is an HTTP-based interface created for developers keen on building bots for Telegram“. After creating this bot with the help of @botfather and obtaining an API key, it was easy to interact with it. Using GET requests, you can ask for all the messages received by your bot. The response comes nicely formatted in JSON mark-up language.
  • Python – Why we’ve chosen Python? It’s easier to understand for beginners, has libraries already available for making web requests and parsing JSON responses.
  • High level bot functionality: Get weather from Open Weather Map, using their API.

I’ve also practised working with various tools (Github, Trello) that helped manage the project in a smart and agile way.

  • For example the Trello board below was used to log issues, feature requests, testing and updates:

So far it’s been an exciting learning experience. The great thing is that LanaBot aims to learn new things and become really smart. She’s now focusing on learning how to:

  1. Deploy the bot on a Raspberry Pi and take pictures: python picamera
  2. Send motivational quotes from a database

Leave a Reply

Your email address will not be published. Required fields are marked *