def bridge_off(message): """Turn off bridge temporarily Message has the following format: /bridgeOff Args: message: Received Telegram message. """ if message.chat.type not in ['group', 'supergroup']: tgbot.reply_to(message, 'This operation can be done only in a group') return # Check if it already exists wa_group_name = db_get_contact_by_group(message.chat.id) if not wa_group_name: tgbot.reply_to(message, 'This group is not bridged to anywhere') return db_toggle_bridge_by_tg(message.chat.id, False) tgbot.reply_to( message, 'Bridge has been turned off. Use `/bridgeOn` to turn it back on')
def relay_group_wa(message): """ Send a message received in a bound group to the correspondending contact through Whatsapp. Args: message: Received Telegram message. """ cid = message.chat.id if db_is_bridge_enabled_by_tg(cid) == False: return uid = message.from_user.id text = "<" + message.from_user.first_name + ">: " + message.text #if uid != SETTINGS['owner']: # tgbot.reply_to(message, 'you are not the owner of this bot') # return name = db_get_contact_by_group(group=cid) if not name: logger.info('no user is mapped to this group') #tgbot.reply_to(message, 'no user is mapped to this group') return # Relay logger.info('relaying message to Whatsapp') SIGNAL_WA.send('tgbot', contact=name, message=text)
def handle_docs_audio(message): """ Handle media messages received in Telegram """ # print(message) cid = message.chat.id if not db_is_bridge_enabled_by_tg(cid): return caption = message.caption type = message.content_type name = db_get_contact_by_group(group=cid) if not name: logger.info('no user is mapped to this group') #tgbot.reply_to(message, 'no user is mapped to this group') return link = "https://telegram.dog/dl" if message.forward_from_chat.username: link = "https://telegram.me/" + str( message.forward_from_chat.username) + "/" + str( message.forward_from_message_id) text = " " + message.from_user.first_name + " sent you " + type + \ " with caption " + caption + \ ". \r\nSending large files is not supported by WhatsApp at the moment, \r\n" \ " so switch to Telegram, and revolutionize the new era of messaging only on " + link + "" # print(text) logger.info('relaying message to Whatsapp') SIGNAL_WA.send('tgbot', contact=name, message=text)
def meet_jit_si_NEW_call_h(message): logger.debug('NEW pending feature') cid = message.chat.id name = db_get_contact_by_group(group=cid) reply_message = "Click on this link to join a @GroupCall with all the users. \r\n" if not name: reply_message = "This group is not bridged to anywhere. PLEASE DO NOT ABUSE THIS FREE SERVICE." else: reply_message += "https://meet.jit.si/" + "" + wa_id_to_name( name + str(round(time.time())) + name) tgbot.reply_to(message, reply_message) if name: SIGNAL_WA.send('tgbot', contact=name, message=reply_message)
def bind(message): """Bind a contact to a group. Message has the following format: /bind <name> <group id> Args: message: Received Telegram message. """ if message.chat.id != SETTINGS['owner']: tgbot.reply_to(message, 'You are not the owner of this bot') return # Get name and phone args = telebot.util.extract_arguments(message.text) name, group_id = args.split(maxsplit=1) if not name or not group_id: tgbot.reply_to(message, 'Syntax: /bind <name> <group id>') return group_id = safe_cast(group_id, int) if not group_id: tgbot.reply_to(message, 'Group id has to be a number') return # Ensure contact exists if not get_phone(name): tgbot.reply_to(message, 'No contact found with that name') return # Check if it already exists current = db_get_contact_by_group(group_id) if current: tgbot.reply_to(message, 'This group is already bound to ' + current) return # Add to database db_set_group(name, group_id) tgbot.reply_to(message, 'Bound to group')
def relay_group_wa(message): """ Send a message received in a bound group to the correspondending contact through Whatsapp. Args: message: Received Telegram message. """ cid = message.chat.id uid = message.from_user.id if uid != SETTINGS['owner']: tgbot.reply_to(message, 'you are not the owner of this bot') return name = db_get_contact_by_group(group=cid) if not name: tgbot.reply_to(message, 'no user is mapped to this group') return # Relay logger.info('relaying message to Whatsapp') SIGNAL_WA.send('tgbot', contact=name, message=message.text)
def unlink(message): """Unlink bridge Message has the following format: /unlink Args: message: Received Telegram message. """ if message.chat.type not in ['group', 'supergroup']: tgbot.reply_to(message, 'This operation can be done only in a group') return # Check if it already exists wa_group_name = db_get_contact_by_group(message.chat.id) if not wa_group_name: tgbot.reply_to(message, 'This group is not bridged to anywhere') return # Add to database db_rm_contact(wa_group_name) tgbot.reply_to(message, 'Bridge has been successfully removed.')