How to Build an Interactive Price Quoting Application over Telegram in Python

Using the WhatsMate Telegram Gateway REST API



This article shows you how to build an interactive price quoting application over Telegram in Python. The application responds to user’s requests for price quotes interactively. Don’t know what I am talking about? The following screenshot should explain it more clearly:

Prerequisites:

  1. You need an Enterprise Telegram Gateway API account with WhatsMate.
  2. You have access to a Linux (such as Ubuntu) machine.
  3. Your machine has Python and pip installed.

Video Tutorial:

Steps:

  1. Download the source code package. Alternatively, you can clone the demo repository if you use git.
  2. cd telegram-demos/python
  3. sudo pip install requests Flask
  4. Customize the Python script enterprise-demo-app.py with your account settings on lines 33-47.
  5. Run your application: ./enterprise-demo-app.py

Explanation:

If you are new to Python and want to understand how the script enterprise-demo-app.py works, we are here to help:

  1. Lines 3-4 import the required dependent libraries.
  2. Lines 50-71 define the utility function sendTelegramMessage. Its name already tells you what it does. You don’t need to change it.
  3. Line 75 creates the Flask web framework instance.
  4. Lines 86-103 are the gist of the application. You define how you want to respond to your user’s messages here. The sample program implements a simplistic price quoting engine. Feel free to change it to fit your own needs.
  5. Lines 106-108 kick start the Flask web application server so that it listens on the specified port for incoming webhook events.

What’s Next:

If you are keen to implement an automated interactive application that talks to your users on Telegram, get in touch with one of our technical representatives to sign up for an Enterprise account now.

Want to look at other innovative ideas? Check out the interesting use cases page.

Disclaimer:

  1. We are not affiliated with Telegram in any way. We only provide a gateway for sending out and receiving Telegram messages. We cannot guaranttee the gateway is functional at all times.