Exemple #1
0
def relay_wa(update: Update, context: CallbackContext):
    """Send a message to a contact through Whatsapp.

    Message has the following format:

        /send <name> <message>

    Args:
        message: Received Telegram message.
    """
    #if update.message.chat.id != SETTINGS['owner']:
    #    update.message.reply_text('you are not the owner of this bot')
    #    return

    # Get name and message
    args = update.message.text
    try:
        _, name, text = args.split(' ', 2)

        # Relay
        logger.info('relaying message to Whatsapp')
        SIGNAL_WA.send('tgbot', contact=name, message=text)
    except:
        update.message.reply_text('Syntax: /send <name> <message>')
        return
Exemple #2
0
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)
Exemple #3
0
def relay_wa(message):
    """Send a message to a contact through Whatsapp.

    Message has the following format:

        /send <name> <message>

    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 message
    args = telebot.util.extract_arguments(message.text)
    name, text = args.split(maxsplit=1)

    if not name or not text:
        tgbot.reply_to(message, 'Syntax: /send <name> <message>')
        return

    # Relay
    logger.info('relaying message to Whatsapp')
    SIGNAL_WA.send('tgbot', contact=name, message=text)
Exemple #4
0
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)
Exemple #5
0
def meet_jit_si_NEW_call_h(update: Update, context: CallbackContext):
    logger.debug('NEW pending feature')
    cid = update.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)
    update.message.reply_text(reply_message)
    if name:
        SIGNAL_WA.send('tgbot', contact=name, message=reply_message)
Exemple #6
0
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)
Exemple #7
0
def relay_group_wa(update: Update, context: CallbackContext):
    """ Send a message received in a bound group to the correspondending contact through Whatsapp.

    Args:
        message: Received Telegram message.
    """

    if update.message.text in ['/jc', '/joincall']:
        meet_jit_si_NEW_call_h(update, context)
        return

    cid = update.message.chat.id

    if not db_is_bridge_enabled_by_tg(cid):
        return

    uid = update.message.from_user.id
    entities: Dict[telegram.MessageEntity, str] = update.message.parse_entities('text_link')
    message: str = update.message.text
    for i, j in entities.items():
        message = message.replace(j, '[' + j + '](' + i.url + ')')
    text = "<" + update.message.from_user.first_name + ">: " + message

    #if uid != SETTINGS['owner']:
    #    update.message.reply_text('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')
        #update.message.reply_text('no user is mapped to this group')
        return

    # Relay
    logger.info('relaying message to Whatsapp')
    SIGNAL_WA.send('tgbot', contact=name, message=text)
Exemple #8
0
def handle_docs_audio(update: Update, context: CallbackContext):
    """ Handle media messages received in Telegram
    """
    # print(message)
    cid = update.message.chat.id

    if not db_is_bridge_enabled_by_tg(cid):
        return

    name = db_get_contact_by_group(group=cid)
    if not name:
        logger.info('no user is mapped to this group')
        #update.message.reply_text('no user is mapped to this group')
        return
#    elif message.contact
#            or message.location:

    reason = None
    caption = update.message.caption
    attachment = update.message.effective_attachment
    if attachment and isinstance(attachment, (telegram.Video, telegram.Audio, telegram.Document, telegram.VideoNote, telegram.Voice, telegram.Sticker, telegram.Animation)):
        if attachment.file_size < 16 * 10**6:
            file: telegram.File = attachment.get_file()
            path: str = './DOWNLOADS/' + attachment.file_id + mimetypes.guess_extension(attachment.mime_type)
            file.download(custom_path=path)
            logger.info('relaying media message to Whatsapp')
            caption: str = get_type_string(update.message) + ': <' + update.message.from_user.first_name + '>' + (': ' + caption if caption else '')
            media: DataMedia = DataMedia(path, get_type_string(update.message), caption)
            if yowsup_cli_supports_sending_media:
                SIGNAL_WA.send('tgbot', contact=name, media=media)
            else:
                os.system('scp ' + path + ' ' + SETTINGS['public_path'])
                SIGNAL_WA.send('tgbot', contact=name, message=caption + ' at ' + SETTINGS['public_reachable'] + path.split('/')[len(path.split('/')) - 1])
            return
        else:
            reason = 'the Media is too large for Whatsapp'
    elif attachment and type(attachment) == list and isinstance(attachment[0], telegram.PhotoSize):
        for i in attachment:
            if attachment.size < 16 * 10 ** 6:
                file: telegram.File = attachment.get_file()
                path: str = './DOWNLOADS/' + attachment.file_id + mimetypes.guess_extension(attachment.mime_type)
                file.download(custom_path=path)
                logger.info('relaying media message to Whatsapp')
                caption: str = get_type_string(update.message) + ': <' + update.message.from_user.first_name + '>' + (
                    ': ' + caption if caption else '')
                media: DataMedia = DataMedia(path, get_type_string(update.message), caption)
                if yowsup_cli_supports_sending_media:
                    SIGNAL_WA.send('tgbot', contact=name, media=media)
                else:
                    os.system('scp ' + path + ' ' + SETTINGS['public_path'])
                    SIGNAL_WA.send('tgbot', contact=name,
                                   message=caption + ' at ' + SETTINGS['public_reachable'] + path.split('/')[
                                       len(path.split('/')) - 1])
                return
            else:
                reason = 'the Media is too large for Whatsapp'
    elif attachment and isinstance(attachment, telegram.Contact):
        contact: telegram.Contact = attachment
        vcard: str = contact.vcard
        path: str = create_unique_filepath('./DOWNLOADS/contact.vcard')
        with open(path, 'w') as f:
            for i in vcard.split('\n'):
                f.write(i)
        media: DataMedia = DataMedia(path, 'document')
        if yowsup_cli_supports_sending_media:
            SIGNAL_WA.send('tgbot', contact=name, media=media)
        else:
            os.system('scp ' + path + ' ' + SETTINGS['public_path'])
            SIGNAL_WA.send('tgbot', contact=name,
                           message='Contact at ' + SETTINGS['public_reachable'] + path.split('/')[
                               len(path.split('/')) - 1])
        return
    elif attachment and isinstance(attachment, telegram.Location):
        location: telegram.Location = attachment
        media: Location = Location(location.longitude, location.latitude)
        logger.info('relaying location to Whatsapp')
        SIGNAL_WA.send('tgbot', contact=name, media=media)
        return
    elif attachment:
        reason = get_reason_string(update.message)
    if reason:
        name = db_get_contact_by_group(group=cid)
        type = get_type_string(update.message)
        if not name:
            logger.info('no user is mapped to this group')
            #update.message.reply_text('no user is mapped to this group')
            return
        if not caption:
            caption = ''
        link = "https://telegram.dog/dl"
        if update.message.chat.type == 'group':
            link = 'https://t.me/' + update.message.chat.id
        elif update.message.chat.type == 'supergroup':
            link = update.message.link

        text = " " + update.message.from_user.first_name + " sent you " + type + \
	       " with caption " + caption + \
    	   " \nsadly this is not supported bechause " + reason+ \
            "\nIf you want to view this, go to " + link + " or create your own account."
        # print(text)
        logger.info('relaying sorry message to Whatsapp')
        SIGNAL_WA.send('tgbot', contact=name, message=text)