Here’s the version which I use, which uses Telegram as the transport layer:
"""
Derived from Matt Potma's basic telegram bot usage script.
Utilizes this API Library:
https://github.com/python-telegram-bot/python-telegram-bot
To install:
pip install python-telegram-bot --upgrade
In ~/.telegram on the machine running the job, put
{"api_key": "462203107:<your API key>",
"chat_id": "<your chat ID>"}
Here's how you get an API key:
https://core.telegram.org/api/obtaining_api_id
Here's how you get your chat ID:
https://stackoverflow.com/questions/32423837/telegram-bot-how-to-get-a-group-chat-id
"""
import telegram
import json
import os
def notify_me(message="Job's done!"):
filename = os.environ['HOME'] + '/.telegram'
with open(filename) as f:
json_blob = f.read()
credentials = json.loads(json_blob)
# Initialize bot
bot = telegram.Bot(token=credentials['api_key'])
# Send message
bot.send_message(chat_id=credentials['chat_id'], text=message)
I just use it to tell me the job is over (so I can turn off the instance and not keep racking up charges), but it would be easy to change to provide information about the run.