Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
tips:telegram [2016/11/09 16:22] – scipio | tips:telegram [2022/04/12 08:07] (current) – sscipioni | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Telegram ====== | ====== Telegram ====== | ||
+ | |||
+ | {{tag> | ||
+ | |||
+ | ===== channel ===== | ||
+ | |||
+ | send message to channel from bot (BOT_API_KEY required): | ||
+ | - add bot to channel as admin | ||
+ | - send message | ||
+ | |||
+ | < | ||
+ | curl https:// | ||
+ | </ | ||
+ | |||
===== BOT ===== | ===== BOT ===== | ||
Line 11: | Line 24: | ||
registrare un webhook (consigliato) | registrare un webhook (consigliato) | ||
< | < | ||
- | pip install python-telegram-bot | + | pip install python-telegram-bot |
ipython | ipython | ||
Line 48: | Line 61: | ||
==== Add BOT to group ==== | ==== Add BOT to group ==== | ||
- | * With BotFather click / | + | |
- | * Add to group @BOT | + | * Add @BOT to group |
- | * Send a message to group | + | * Send a message to group |
- | * Give .result.message.chat.id from curl https:// | + | * Give .result.message.chat.id from curl https:// |
+ | <code bash> | ||
+ | TOKEN= | ||
+ | curl https:// | ||
+ | </ | ||
Send a message to group | Send a message to group | ||
- | {{{ | + | <code bash> |
- | curl -X POST " | + | TOKEN= |
- | }}} | + | CHATID= |
+ | curl -X POST " | ||
+ | </ | ||
- | ===== Desktop Installer ===== | + | To enable BOT to receive messages from group disable "group privacy" |
+ | ==== curl ==== | ||
+ | |||
+ | send message | ||
<code bash> | <code bash> | ||
- | #!/bin/bash | + | #/bin/sh |
- | + | ||
- | echo " | + | |
- | echo " | + | |
- | echo " | + | |
- | echo " | + | |
- | echo " | + | |
- | + | ||
- | echo " | + | |
- | + | ||
- | cd /tmp | + | |
- | wget -O - https:// | + | |
- | wget -O - https:// | + | |
- | + | ||
- | echo " | + | |
- | + | ||
- | sudo mkdir / | + | |
- | sudo chmod +x / | + | |
- | + | ||
- | echo " | + | |
- | + | ||
- | tar -xvJf tsetup.tar.gz | + | |
- | cd ./ | + | |
- | + | ||
- | echo " | + | |
- | sudo cp ./Updater / | + | |
- | sudo cp ./Telegram / | + | |
- | user=$(whoami) | + | |
- | sudo chown -R $user:$user / | + | |
- | + | ||
- | echo " | + | |
- | + | ||
- | cd /tmp | + | |
- | + | ||
- | sudo echo " | + | |
- | sudo echo " | + | |
- | sudo echo " | + | |
- | sudo echo " | + | |
- | sudo echo " | + | |
- | sudo echo " | + | |
- | sudo echo " | + | |
- | sudo echo " | + | |
- | sudo echo " | + | |
- | sudo echo " | + | |
- | + | ||
- | sudo cp icon.png / | + | |
- | sudo cp telegram.desktop / | + | |
- | + | ||
- | echo " | + | |
- | + | ||
- | rm / | + | |
- | rm / | + | |
- | rm / | + | |
- | rm -R / | + | |
- | + | ||
- | + | ||
- | echo " | + | |
- | + | ||
- | / | + | |
+ | API=" | ||
+ | CHATID=123456 | ||
+ | TEXT=" | ||
+ | |||
+ | curl --data chat_id=$CHATID --data-urlencode " | ||
</ | </ | ||
+ | ===== bot video ===== | ||
+ | |||
+ | <code python> | ||
+ | # | ||
+ | # -*- coding: utf-8 -*- | ||
+ | """ | ||
+ | |||
+ | # This program is dedicated to the public domain under the CC0 license. | ||
+ | """ | ||
+ | |||
+ | TOKEN=" | ||
+ | AUTHORIZED=[73496590, | ||
+ | |||
+ | import logging | ||
+ | from telegram import InlineKeyboardButton, | ||
+ | from telegram.ext import Updater, CommandHandler, | ||
+ | import subprocess | ||
+ | |||
+ | logging.basicConfig(format=' | ||
+ | level=logging.INFO) | ||
+ | logger = logging.getLogger(__name__) | ||
+ | |||
+ | |||
+ | def _isAuthorized(update): | ||
+ | isOk = update.effective_user[' | ||
+ | if not isOk: | ||
+ | update.message.reply_text(' | ||
+ | return isOk | ||
+ | | ||
+ | | ||
+ | def reply(update, | ||
+ | reply_keyboard = [['/ | ||
+ | update.message.reply_text(message, | ||
+ | | ||
+ | |||
+ | def start(bot, update): | ||
+ | if _isAuthorized(update): | ||
+ | reply(update, | ||
+ | # | ||
+ | |||
+ | def show(bot, update): | ||
+ | print(" | ||
+ | if _isAuthorized(update): | ||
+ | user_id = update.effective_user[' | ||
+ | subprocess.call(["/ | ||
+ | reply(update, | ||
+ | |||
+ | def motion(bot, update): | ||
+ | print(" | ||
+ | if _isAuthorized(update): | ||
+ | user_id = update.effective_user[' | ||
+ | reply(update, | ||
+ | subprocess.call(["/ | ||
+ | |||
+ | def error(bot, update, error): | ||
+ | """ | ||
+ | logger.warning(' | ||
+ | |||
+ | |||
+ | def previewday(bot, | ||
+ | if _isAuthorized(update): | ||
+ | user_id = update.effective_user[' | ||
+ | message = update.message[' | ||
+ | camera = message[0] | ||
+ | try: | ||
+ | speed = int(message[1]) | ||
+ | except: | ||
+ | speed = 50 | ||
+ | reply(update, | ||
+ | makedayvideo(user_id, | ||
+ | |||
+ | |||
+ | def makedayvideo(user_id, | ||
+ | print(["/ | ||
+ | subprocess.call(["/ | ||
+ | |||
+ | def button(bot, update): | ||
+ | query = update.callback_query | ||
+ | chat_id=query.message.chat_id | ||
+ | |||
+ | bot.edit_message_text(text=' | ||
+ | makedayvideo(chat_id, | ||
+ | |||
+ | |||
+ | def buttonpreview(bot, | ||
+ | if _isAuthorized(update): | ||
+ | keyboard = [[InlineKeyboardButton(" | ||
+ | InlineKeyboardButton(" | ||
+ | InlineKeyboardButton(" | ||
+ | InlineKeyboardButton(" | ||
+ | InlineKeyboardButton(" | ||
+ | ]] | ||
+ | reply_markup = InlineKeyboardMarkup(keyboard) | ||
+ | update.message.reply_text(' | ||
+ | |||
+ | def main(): | ||
+ | updater = Updater(TOKEN) | ||
+ | |||
+ | updater.dispatcher.add_handler(CommandHandler(' | ||
+ | updater.dispatcher.add_handler(CommandHandler(' | ||
+ | updater.dispatcher.add_handler(CommandHandler(' | ||
+ | updater.dispatcher.add_handler(CommandHandler(' | ||
+ | updater.dispatcher.add_handler(CommandHandler(' | ||
+ | updater.dispatcher.add_handler(CommandHandler(' | ||
+ | updater.dispatcher.add_handler(CommandHandler(' | ||
+ | updater.dispatcher.add_handler(CommandHandler(' | ||
+ | updater.dispatcher.add_handler(CommandHandler(' | ||
+ | updater.dispatcher.add_handler(CallbackQueryHandler(button)) | ||
+ | updater.dispatcher.add_error_handler(error) | ||
+ | |||
+ | updater.start_polling() | ||
+ | updater.idle() | ||
+ | |||
+ | |||
+ | if __name__ == ' | ||
+ | main() | ||
+ | </ | ||
+ | |||
+ | |||
+ |