Esempio n. 1
0
def send_batch_facebook_message(fb_ids, message):
    """
    Send same message to all fb_id
    """
    post_message_url = 'https://graph.facebook.com/v2.6/me/messages?access_token=' + ACCESS_TOKEN
    response_msgs = []

    for i in range(len(fb_ids)):
        response_msgs.append(json.dumps(
            {
                "recipient": {
                    "id": str(fb_ids[i])
                },
                "messaging_type": "MESSAGE_TAG",  # Messaging type is MESSAGE_TAG, NON_PROMOTIONAL_SUBSCRIPTION
                "tag": "NON_PROMOTIONAL_SUBSCRIPTION",
                "message": message
            })
        )

    CLIENT.send_fb_messages_async(post_message_url, response_msgs)

    if not settings.is_prod():
        logger.log(response_msgs)

    return response_msgs
Esempio n. 2
0
    def log(self, message, forward):
        if not self.enabled:
            return

        print(message)

        if forward and settings.is_prod():
            # Only send in production mode
            self.logger.info(message)
Esempio n. 3
0
def send_facebook_message(fb_id, message):
    response_msg = json.dumps({
        "recipient": {
            "id": fb_id
        },
        "messaging_type": "RESPONSE",  # Messaging type is RESPONSE
        "message": message
    })

    CLIENT.send_fb_message(GRAPH_URL, response_msg)

    if not settings.is_prod():
        logger.log(response_msg)

    return response_msg
Esempio n. 4
0
def send_facebook_message(fb_id, message):
    post_message_url = 'https://graph.facebook.com/v2.6/me/messages?access_token=' + ACCESS_TOKEN
    response_msg = json.dumps(
        {
            "recipient": {
                "id": fb_id
            },
            "messaging_type": "RESPONSE", # Messaging type is RESPONSE
            "message": message
        })

    CLIENT.send_fb_message(post_message_url, response_msg)

    if not settings.is_prod():
        logger.log(response_msg)

    return response_msg
Esempio n. 5
0
    def run_task(self, options):
        all_ids = user_manager.get_all_users_id()

        text = "UEFA Nations League starts tonight! " + EMOJI_TROPHY + EMOJI_FIRE \
               + '\n\n' + "The newly created competition between european national teams will make its debut tonight!"\
               + '\n\n' + "SUBSCRIBE now to not miss a single match."

        messages = []

        # image asset id
        asset_id = 2183629061849013 if settings.is_prod() else 661776840874725

        messages.append(
            formatter.create_image_attachment_from_saved_asset(asset_id))

        messages.append(
            formatter.create_quick_text_reply_message(text, [
                EMOJI_TROPHY + ' Add Nations League',
                EMOJI_CROSS + ' No thanks'
            ]))

        sender.send_batch_multiple_facebook_messages(all_ids, messages)
Esempio n. 6
0
def send_batch_multiple_facebook_messages(fb_ids, messages):
    """
    Send multiple messages to all fb_id (2 or more message in a row to the same user)
    Does this in a chunk manner so people get the message at the same time in order
    """
    response_msgs = []
    messages_to_send = []

    def chunks(l, n):
        """Yield successive n-sized chunks from list l"""
        for i in range(0, len(l), n):
            yield l[i:i + n]

    for fb_ids_chunk in chunks(fb_ids, 50):  # choose chunks of 50

        for message in messages:

            for fb_id in fb_ids_chunk:

                fb_message = json.dumps({
                    "recipient": {
                        "id": str(fb_id)
                    },
                    "messaging_type":
                    "MESSAGE_TAG",  # Messaging type is MESSAGE_TAG, NON_PROMOTIONAL_SUBSCRIPTION
                    "tag": "NON_PROMOTIONAL_SUBSCRIPTION",
                    "message": message
                })

                messages_to_send.append(fb_message)
                response_msgs.append(fb_message)

            CLIENT.send_fb_messages_async(GRAPH_URL, messages_to_send)
            messages_to_send = []

    if not settings.is_prod():
        logger.log(response_msgs)

    return response_msgs
Esempio n. 7
0
def send_batch_facebook_message(fb_ids, message):
    """
    Send same message to all fb_id
    """
    response_msgs = []

    for i in range(len(fb_ids)):
        response_msgs.append(
            json.dumps({
                "recipient": {
                    "id": str(fb_ids[i])
                },
                "messaging_type":
                "MESSAGE_TAG",  # Messaging type is MESSAGE_TAG, NON_PROMOTIONAL_SUBSCRIPTION
                "tag": "NON_PROMOTIONAL_SUBSCRIPTION",
                "message": message
            }))

    CLIENT.send_fb_messages_async(GRAPH_URL, response_msgs)

    if not settings.is_prod():
        logger.log(response_msgs)

    return response_msgs
Esempio n. 8
0
def _send_to_logentries(log):
    if settings.is_prod():
        # Only send in production mode
        LOGGER.info(log)