def command_on_message(update): # check if message is in update if not 'message' in update: return # get message from update message = update['message'] msg_id = message['id'] msg_chat_id = message['chat_id'] msg_content = get_message_as_text(message) if msg_content == '.chat': pretty_print( bmodes.DBG, f"Chat: {colored(f'#{msg_chat_id}', 'magenta')}, Message: {colored(f'#{msg_id}', 'magenta')}" ) if settings['del-edit-detector']['enable']['delete'] or s['del-edit-detector'][ 'enable']['edit']: tg.add_message_handler(detector_on_message) tg.add_update_handler('updateDeleteMessages', detector_on_messages_delete) tg.add_update_handler('updateMessageEdited', on_message_edit) if settings['forwarder']['enable']: tg.add_message_handler(forwarder_on_message) tg.add_message_handler(command_on_message) tg.idle()
tg = Telegram(api_id=args.api_id, api_hash=args.api_hash, phone=args.phone, td_verbosity=5, files_directory=os.path.expanduser("~/.telegram/" + args.phone), database_encryption_key=args.dbkey) tg.login() # if this is the first run, library needs to preload all chats # otherwise the message will not be sent r = tg.get_chats() r.wait() r = tg.call_method( 'createCall', { 'user_id': args.user_id, 'protocol': { 'udp_p2p': True, 'udp_reflector': True, 'min_layer': 65, 'max_layer': 65 } }) r.wait() outgoing = r.update tg.add_handler(handler) tg.idle() # blocking waiting for CTRL+C
from telegram.client import Telegram from json import dumps from secret import * client = Telegram( api_id=API_ID, api_hash=API_HASH, phone=PHONE_NUMBER, database_encryption_key=DBENC, ) client.login() def new_message_handler(update): print(dumps(update['message']['chat_id'], indent=4)) if str(update['message']['chat_id']) == CHAT_ID_SENDER: print(dumps(update, indent=4)) message_content = update['message']['content'].get('text', {}) message_entities = message_content.get('entities', '') message_text = message_content.get('text', {}) print('\n\n\n', 'Encaminhando mensagem', '\n\n\n') client.send_message( chat_id=CHAT_ID_RECEIVER, text=message_text, ) client.add_message_handler(new_message_handler) client.idle()