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:
- You need an Enterprise Telegram Gateway API account with WhatsMate.
- You have access to a Linux (such as Ubuntu) machine.
- Your machine has
Python
andpip
installed.
Video Tutorial:
Steps:
- Download the source code package. Alternatively, you can clone the demo repository if you use git.
cd telegram-demos/python
sudo pip install requests Flask
- Customize the Python script
enterprise-demo-app.py
with your account settings on lines 33-47. - 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:
- Lines 3-4 import the required dependent libraries.
- Lines 50-71 define the utility function
sendTelegramMessage
. Its name already tells you what it does. You don’t need to change it. - Line 75 creates the
Flask
web framework instance. - 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.
- 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:
- 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.