How to send Telegram Messages in Python

Using the WhatsMate Telegram Gateway REST API



This article shows you how to send a Telegram message in Python.

Before the recipient can receive your Telegram message, she will need to register with the WhatsMate Telegram Gateway. Instructions are available on the official site. Unregistered users will never receive messages from the Gateway.

To send a Telegram message from a Python script, do this:

  1. Copy the following source code to your Python script.
  2. Customize the TODO lines:
    • Specify your gateway instance ID on line 6.
    • Specify your client ID and secret on lines 7 and 8.
    • Specify your target recipient on line 11. Remember to include the country code.
    • Specify your message on line 12.
  3. Install the Requests library because the sample script depends on it: pip install requests
  4. Make your script executable: chmod 755 send-telegram.py
  5. Run the script to see the result: ./send-telegram.py

You will need a trial account to call the above API. Go sign up now.