Telegram бот для постинга записей в каналы, где бот находится или в личку.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Vladimir Smagin 7d2f845591 Изменить 'readme.md' 3 weeks ago
helpers import 1 year ago
bot.py Изменить 'bot.py' 1 year ago
readme.md Изменить 'readme.md' 3 weeks ago
requirements.txt import 1 year ago
run import 1 year ago
telegram-post-bot.service import 1 year ago

readme.md

Telegram-post-bot

This is my Telegram bot that can accept messages in JSON from port or socket file and forward to group, channel or private person.

Requires python 3 libs:

  • wheel
  • python-telegram-bot
  • raven (if you using Sentry)

Best results if you install it to venv or use in Docker image.

Deploy in Docker

To run prepare this ENV variables

  • ENV_TELEGRAM_TOKEN=telegram_bot_token Register new bot and get token with @BotFather bot.
  • ENV_RAVEN_TOKEN=sentry.io_token Set this variable only if you use Sentry error reporting.
  • USEIP=true Required in Docker, opens port instead of socket file.

Now you are ready to start image:

docker run --name telegram-post-bot -p 10010:10021 \
    -e TELEGRAM_API_TOKEN=$ENV_TELEGRAM_TOKEN \
    -e RAVEN_TOKEN=$ENV_RAVEN_TOKEN \
    -e USEIP=true \
    iam21h/telegram-post-bot

Sample alert script for Zabbix

See more here https://blindage.org/?p=9548

#!/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

Run:

>$ alert_script.sh "Message title" "Message text body"

Change nc call from socket file to port if use docker image.