INT 21h

Select language

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: There was a young girl from the coast Who, just when she needed it most, Lost her Kotex and bled All over the bed, And the head and the beard of her host.