Build a Shipment Tracking Tool using a Telegram Bot
Design a Telegram Bot that will interact with truck drivers to track your shipments and provide real-time visibility of your transportation performance
Design a Telegram Bot that will interact with truck drivers to track your shipments and provide real-time visibility of your transportation performance
Article originally published on Medium.
Retailers and FMCG companies are facing increasing pressure to improve their supply chain, increase their flexibility and reduce costs.
Using Distribution Centers (DC) is an effective solution, as they allow a single location to stock a vast range of products coming from different suppliers close to the final customer.
However, it should be coupled with efficient tracking of the shipments to provide stores with accurate ETAs, ensure transparency of delivery processes and measure performance.
I. Limitation of TMS & Tracking Tools
Example
You are a medium-size retailer operating in a market where the transportation industry is not mature.
You would like to implement a Transport Management System (TMS) proposed by an external provider to get full visibility and real-time tracking of your shipments.
What kind of obstacles can you face?
- System Interface: you have multiple carriers with different systems
- Maturity of Carriers: they manage their fleet with manual processes (Excel)
- Local Specifics: carriers do not operate their own fleet (sub-contracting)
- Limited Capacity to Negotiate: because your volumes are low compared to other customers carriers refuse to adapt their processes and use your system to record status
If you are facing these obstacles, the solution presented in this article will probably answer your needs.
II. What do we need here?
A simple, cheap and easy-to-implement solution to track your shipments that
- Does not require additional IT development for your carriers
- Easily integrates into the current transportation processes
- Reduces admin workload for your logistics team
- Does not impact drivers’ productivity
- Does not require additional equipment
- Provides visibility, real-time tracking and transparency
III. What is a Telegram Bot?
Telegram
Telegram is a secure, convenient messaging app that’s cross-platform, meaning it works on all of your devices. With more than 500 million users worldwide, Telegram has an open API and protocol free for everyone. With this API we can build our own tools including a bot.
What’s a Bot?
A bot is a 3rd party application that can interact with users by sending them messages, commands and inline requests. With Telegram, you can design and control your Telegram bot by sending HTTPS requests to their bot API.
Your bot can send/receive messages, photos, videos and GPS locations — enough to build our shipment tracking tool.
How to interact with a Telegram Bot?
Add him and start a conversation :)
IV. Create your Tracking Assistant Bot
Standard Operating Model (SOP)
For the first version of our bot, let us take a light version of SOP to record delivery time.
Confirm Unloading at Destination
- STORE TEAM finished unloading your shipment from the truck
- DRIVER shares Shipment Number, GPS location and a picture of the shipment with your Telegram BOT to confirm delivery
- Telegram BOT sends a delivery notification by email to your logistics team with the information listed above
Edit: You can find a Youtube version of this article with animations in the link below.
V. Demo: Shipment Delivery confirmation
Scenario
Your shipment has been unloaded in your store. DRIVER wants to send delivery confirmation before leaving for his next destination.
Step 1: DRIVER opens telegram and starts a discussion with BOT
Step 2: DRIVER shares its GPS Location (= Store Location)
Step 3: DRIVER shares a delivery number
Step 4: DRIVER shares a picture of the shipment
Step 5: Your logistics teams receive a shipment confirmation
VII. Design your Telegram Bot
1. Create your bot with another bot :)
@ BotFather is a Telegram bot that will help you create your own bot
- Search @ BotFather on Telegram and send him ‘/start’
- Answer ‘/newbot’ message and follow instructions to set up a name and a username
- Your bot is now ready, with an API token created — please keep a copy of this token!
2. Installing Python packages
Package to manage your telegram bot
3. Import Libraries and enable logging
TOKEN: shared by @ BotFather when you created your bot
APP_NAME: address of your Heroku application (see steps below)
4. Main function with Conversation handler
To simplify the process for the DRIVER, your BOT will ask for information in sequence using the ConversationHandler function of Telegram API
Example of photo function
- photo_file: extract the last photo uploaded in the messages written by the user
- link1: link created by Telegram API where we can extract photo file id
- link2: web page created by Telegram API that hosts this photo
- mail function: send an email with delivery_number, gps_location and embedded photo using HTML
For more details regarding Telegram API, I strongly suggest checking the list of reference links at the end of the article.
5. Mail Function
After collecting the Delivery Number, GPS Location and shipment picture your bot will send a notification by email to your transportation team using smtplib python package and Gmail account.
You can find the mail function in the script mail.py.
6. Host your bot on the cloud
Heroku is a cloud-based service where you can host your web application; the free formula of hosting provides enough resources to run your app.
Two files listed above are needed to set up your app on Heroku.
You can find detailed instructions on how to deploy your Telegram bot on Heroku in this good medium article written by Haohui (Link).
Next Steps
This is a very light version to show the potential of what can be done with a Telegram Bot.
We can improve it by adding
- Real-Time GPS Location Tracking
- Store records in a database /OR/ google sheet
- Add scanning function (Bar Code/QR Code) to avoid manual entry of delivery number by DRIVER
- A function to get store comments and driver comments in case of late delivery?
- Seals management in case of shipping sensitive goods
About Me
Let’s connect on Linkedin and Twitter, I am a Supply Chain Engineer that is using data analytics to improve logistics operations and reduce costs.
References
Many details were skipped in this article to make it concise and easy to read. You can find detailed instructions in the excellent articles listed below.
[1] — Dzaky Widya, Learn to build your first bot in Telegram with Python, freecodecamp.org
[2]— Haohui, How to Deploy a Telegram Bot using Heroku for FREE, Medium
[3] — Ng Wai Foong, How to Create Telegram Bot in Python, Medium