INT 21h

Hi, I am Vladimir Smagin, SysAdmin and Kaptain. Telegram Email / GIT / RSS / GPG

Python bot for posting notifications to Telegram channels, groups or private

№ 9465 В разделе "Programming" от October 21st, 2018,
В подшивках: ,

This bot can accept messages from another applications through socket file connection and post it to Telegram. You can use it for posting notifications from Git hooks, tasks in cron, weather and another sources.

Sample message:

{"chatID":"@radio70logbook","message":"test"}

Example script: send Zabbix notifications to Telegram channel

#!/bin/bash
source /etc/profile

json_escape () {
    printf '%s' "$1" | python -c 'import json,sys; print(json.dumps(sys.stdin.read()).strip("\""))'
}

chat_id="-3459475309874"
post_title=$(json_escape "$1")
post_body=$(json_escape "$2")

echo "{\"chatID\":\"${chat_id}\",\"message\":\"${post_title}\n\n${post_body}\"}" | \
    nc -U /run/telegram-GrapeBlessedBot.sock

Source code:

https://git.blindage.org/21h/telegram-post-bot

Нет комментариев »

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Яндекс.Метрика

Fortune cookie: "Missionaries are perfect nuisances and leave every place worse than they found it." [Charles Dickens]