Giter VIP home page Giter VIP logo

heyoo's Introduction

Made in Tanzania Downloads Downloads Downloads

Unofficial Python wrapper for the WhatsApp Cloud API

Supported features

  1. Sending messages
  2. Marking messages as read
  3. Sending Media (images, audio, video and documents)
  4. Sending location
  5. Sending interactive buttons
  6. Sending template messages
  7. Parsing messages and media received

Getting started

To get started with heyoo, you have to firstly install the library either directly or using pip.

Building from source

Use git to clone or you can also manually download the project repository just as shown below;

$ git clone https://github.com/Neurotech-HQ/heyoo
$ cd heyoo
heyoo $ python setup.py install 

Installing via pip

# For Windows 

pip install  --upgrade heyoo

#For Linux | MAC 

pip3 install --upgrade heyoo

Running on Docker

To run an instance in docker run the commands below

$ docker compose build
$ docker compose up

Setting up

To get started using this package, you will need TOKEN and TEST WHATSAPP NUMBER (the library works either with a production phone number, if you have one) which you can get from the Facebook Developer Portal

Here are steps to follow for you to get started:

  1. Go to your apps
  2. create an app
  3. Select Business >> Business
  4. It will prompt you to enter basic app informations
  5. It will ask you to add products to your app a. Add WhatsApp Messenger
  6. Right there you will see a your TOKEN and TEST WHATSAPP NUMBER and its phone_number_id
  7. Lastly verify the number you will be using for testing on the To field.

Once you've followed the above procedures you're ready to start hacking with the Wrapper.

Authentication

To authenticate your application, you need to specify the TOKEN and the phone_number_id of your application

>>> from heyoo import WhatsApp
>>> messenger = WhatsApp('TOKEN',  phone_number_id='104xxxxxx')

Once you have authenticated your app you can start using the above mentioned feature as shown above;

It is only possible to send messages other than templates only after the target phone responds to an initial template message or sends a message first. This resets every 24 hours; after that, you need to send a template again or the message won't be delivered. Reference: https://developers.facebook.com/community/threads/425605939396247/

Logging

You can configure your own log level. This is an example to set the log level to info. By default only Error messages are logged.

import logging

logging.basicConfig(
    level=logging.INFO,
    format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
)

Sending Messanges

Use this method to send text message to a WhatsApp number.

>>> messenger.send_message('Your message ', 'Mobile eg: 255757xxxxx')

Marking messages as read

Use this method to mark a previously sent text message as read.

>>> messenger.mark_as_read('Message ID')

Sending Images

When sending media(image, video, audio, gif and document ), you can either specify a link containing the media or specify object id, you can do this using the same method.

By default all media methods assume you're sending link containing media but you can change this by specifying the link=False.

Here an example;

>>> messenger.send_image(
        image="https://i.imgur.com/Fh7XVYY.jpeg",
        recipient_id="255757xxxxxx",
    )

Note: You can also send media from your local machine but you have to upload it first to Whatsapp Cloud API, you can do this using the upload_media method. and then use the returned object id to send the media.

Here an example;

>>> media_id = messenger.upload_media(
        media='path/to/media',
    )['id']
>>> messenger.send_image(
        image=media_id,
        recipient_id="255757xxxxxx",
        link=False
    )

Note: Don't forget to set the link to False, and also you can use the same technique for sending video, audio, gif and document from your local machine.

Sending Video

Here an example;

>>> messenger.send_video(
        video="https://www.youtube.com/watch?v=K4TOrB7at0Y",
        recipient_id="255757xxxxxx",
    )

Sending Audio

Here an example;

>>> messenger.send_audio(
        audio="https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3",
        recipient_id="255757xxxxxx",
    )

Sending Document

Here an example;

>>> messenger.send_document(
        document="http://www.africau.edu/images/default/sample.pdf",
        recipient_id="255757xxxxxx",
    )

Sending Location

Here an example;

>>> messenger.send_location(
        lat=1.29,
        long=103.85,
        name="Singapore",
        address="Singapore",
        recipient_id="255757xxxxxx",
    )

Sending Interactive buttons

Here an example;

Note: row button title may not exceed 20 characters otherwise your message will not be sent to the target phone.

>>> messenger.send_button(
        recipient_id="255757xxxxxx",
        button={
            "header": "Header Testing",
            "body": "Body Testing",
            "footer": "Footer Testing",
            "action": {
                "button": "Button Testing",
                "sections": [
                    {
                        "title": "iBank",
                        "rows": [
                            {"id": "row 1", "title": "Send Money", "description": ""},
                            {
                                "id": "row 2",
                                "title": "Withdraw money",
                                "description": "",
                            },
                        ],
                    }
                ],
            },
        },
    )

Sending Interactive reply buttons

Here an example;

Send reply button only displays three reply buttons, if it exceeds three reply buttons, it will raise an error and your message will not be sent.

>>> messenger.send_reply_button(
        recipient_id="255757xxxxxx",
        button={
            "type": "button",
            "body": {
                "text": "This is a test button"
            },
            "action": {
                "buttons": [
                    {
                        "type": "reply",
                        "reply": {
                            "id": "b1",
                            "title": "This is button 1"
                        }
                    },
                    {
                        "type": "reply",
                        "reply": {
                            "id": "b2",
                            "title": "this is button 2"
                        }
                    }
                ]
            }
      },
    )

Sending a Template Messages

Here how to send a pre-approved template message, Template messages can either be;

  1. Text template
  2. Media based template
  3. Interactive template

You can customize the template message by passing a dictionary of components.

IMPORTANT: components are also known as variable parameters (like {{0}} or {{1}}) which are used to include variables into a message. You can find the available components in the documentation. https://developers.facebook.com/docs/whatsapp/cloud-api/guides/send-message-templates

>>> messenger.send_template("hello_world", "255757xxxxxx", components=[], lang="en_US")

lang is optional but required when sending templates in other languages.

Webhook

Webhook are useful incase you're wondering how to respond to incoming message send by user, but I have created a starter webhook which you can then customize it according to your own plans.

Here an example on how you can use webhook to respond to incoming messages;

  # Handle Webhook Subscriptions
    data = request.get_json()
    logging.info("Received webhook data: %s", data)
    changed_field = messenger.changed_field(data)
    if changed_field == "messages":
        new_message = messenger.get_mobile(data)
        if new_message:
            mobile = messenger.get_mobile(data)
            name = messenger.get_name(data)
            message_type = messenger.get_message_type(data)
            logging.info(
                f"New Message; sender:{mobile} name:{name} type:{message_type}"
            )
            if message_type == "text":
                message = messenger.get_message(data)
                name = messenger.get_name(data)
                logging.info("Message: %s", message)
                messenger.send_message(f"Hi {name}, nice to connect with you", mobile)

            elif message_type == "interactive":
                message_response = messenger.get_interactive_response(data)
                interactive_type = message_response.get("type")
                message_id = message_response[interactive_type]["id"]
                message_text = message_response[interactive_type]["title"]
                logging.info(f"Interactive Message; {message_id}: {message_text}")

            elif message_type == "location":
                message_location = messenger.get_location(data)
                message_latitude = message_location["latitude"]
                message_longitude = message_location["longitude"]
                logging.info("Location: %s, %s", message_latitude, message_longitude)

            elif message_type == "image":
                image = messenger.get_image(data)
                image_id, mime_type = image["id"], image["mime_type"]
                image_url = messenger.query_media_url(image_id)
                image_filename = messenger.download_media(image_url, mime_type)
                print(f"{mobile} sent image {image_filename}")
                logging.info(f"{mobile} sent image {image_filename}")

            elif message_type == "video":
                video = messenger.get_video(data)
                video_id, mime_type = video["id"], video["mime_type"]
                video_url = messenger.query_media_url(video_id)
                video_filename = messenger.download_media(video_url, mime_type)
                print(f"{mobile} sent video {video_filename}")
                logging.info(f"{mobile} sent video {video_filename}")

            elif message_type == "audio":
                audio = messenger.get_audio(data)
                audio_id, mime_type = audio["id"], audio["mime_type"]
                audio_url = messenger.query_media_url(audio_id)
                audio_filename = messenger.download_media(audio_url, mime_type)
                print(f"{mobile} sent audio {audio_filename}")
                logging.info(f"{mobile} sent audio {audio_filename}")

            elif message_type == "document":
                file = messenger.get_document(data)
                file_id, mime_type = file["id"], file["mime_type"]
                file_url = messenger.query_media_url(file_id)
                file_filename = messenger.download_media(file_url, mime_type)
                print(f"{mobile} sent file {file_filename}")
                logging.info(f"{mobile} sent file {file_filename}")
            else:
                print(f"{mobile} sent {message_type} ")
                print(data)
        else:
            delivery = messenger.get_delivery(data)
            if delivery:
                print(f"Message : {delivery}")
            else:
                print("No new message")
    return "ok"

Incase you want a hustle free automatic deployment of the webhook to the Heroku platform, then we have made it simpler for you. With Just a click of a button you can deploy your webhook to Heroku.

steps to Deploy webhook to Heroku

  1. Click the deploy button and the Heroku webpage will open for authentication, after authentication sit back and relax for deployment to finish. Deploy

  2. From Heroku settings configure your Environment varibles of your WhatsAapp application.

  3. Setup and verify your webhook url and token then subscribe to messages.

To learn more about webhook and how to configure in your Facebook developer dashboard please have a look here.

Issues

If you will face any issue with the usage of this package please raise one so as we can quickly fix it as soon as possible;

Contributing

This is an opensource project under MIT License so any one is welcome to contribute from typo to source code or documentation, JUST FORK IT.

References

  1. WhatsApp Cloud API official documentation
  2. Programming WhatsApp is now even easier for Python Developers
  3. Meet Heyoo — an Open-source Python Wrapper for WhatsApp Cloud API
  4. Whatsapp Cloud API: How to send WhatsApp messages from Python?

Related

  1. WhatsApp Cloud API PHP Wrapper
  2. Heyoo Javascript

All the credit

  1. kalebu
  2. All other contributors

heyoo's People

Contributors

claudineibr avatar daudahmad0303 avatar epcosta17 avatar esteban108 avatar filipporomani avatar jaxparrow avatar kalebu avatar leoparente avatar matiasnu avatar mbukh avatar mscansian avatar nikbott avatar noisecontrollers avatar seun-beta avatar sharmakh11597 avatar soerenetler avatar stakewalker avatar taylorgibb avatar tinchoram avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

heyoo's Issues

Messange order

Hi everyone,
I know this is not a problem with heyoo, but maybe it should/cpuld be something to be delt with here. I experience wrong message order on the recieving side of the chatbot when sending several messages directly after one antoher. This happens especially when sending images.

When sending thre images (1.jpg, 2jpg, 3.jpg)

client.send_image("1.jpg", to="xxx")
client.send_image("2.jpg", to="xxx")
client.send_image("3.jpg", to="xxx")

This might result in receiving the images in a different order (1,3,2 or 3,1,2)

Do you have a good way already to change this asynchronous behaviour of the WhatsApp Cloud API? Would this the something of interest for this API?

Best,
Sören

Send_button text may not exceed 20 characters

Hello again,

I would like to propose in the API documentation that we warn the dev that they cannot exceed 20 characters for each button name and row title.

"""
    Send an interactive message with buttons.

    :param button: Button object, rows-title may not exceed 20 characters
    check https://github.com/Neurotech-HQ/heyoo#sending-interactive-reply-buttons for an example.
    :param recipient_id:  Typically the phone number of the recepient
    :return:
"""

Typo in the docs

I believe there is a typo in the code snippet:

intractive_type = message_response.get("type")

Can we change it to interactive?

Not able to send messages to some numbers

While using the code in python, a few numbers were able to receive the message and images, but others did not. The message is sent , but is not received, how to sole this??

Release to PyPI

There were a few changes to the project since the last release in PyPI (feb-2023) is it possible to release a new version?

Split in WhatsAppUpdate and WhatsAppClient

Hi,
i think it would make sense to split the WhatsApp class into a WhatsAppUpdate and WhatsAppClient class. Many of the functions lower in the file like get_location don't actually need the Client. This would make the library easier to handle. One could create a WhatsAppUpdate object from the data and call the get_location on that Only sending messages would need the WhatsAppClient object.
I would be happy to contribute to the project. Let me know what you think about this proposal.

Receiving multiple webhook new message data for single question

Thanks for building this wonderful wrapper.

My problem is -
I am receiving the same new message webhook data multiple times even if it's asked once on WhatsApp.
I visited the issues sections to check comments but this one looks different to me.
I do not have more than one app tied to the same account which was the case for a few.

My app uses langchain and openai internally to generate responses to incoming message. And at times it takes some seconds or even a minute to generate a response. And probably this could be one of the reasons the 200 status ack is delayed and WhatsApp pings the same question to webhook again and again until it receives 200 ack from one of the previous requests.

I am not 100% sure if the above case is true. If it is, I would like to know in the WhatsApp cloud API account -

  • how can we extend the time window? or
  • how can we reduce the retries to 1?

If not, how can we handle the delay in the code itself?

Any help will be appreciated, Thanks!

@Kalebu @filipporomani

Not able to send text messages

While sending text messages without any template, getting 200 response but message is not being received by the target phone phone.

Key error in changed_field for webhook

I am testing the application and I used the whatsapp api webhook tests but the messenger.changed_field function fails to catch the data:

webhook data: {'entry': [{'id': '0', 'time': 1675274553, 'uid': '0', 'changed_fields': ['location']}], 'object': 'user'} {'entry': [{'id': '0', 'time': 1675274553, 'uid': '0', 'changed_fields': ['location']}], 'object': 'user'}

With this function:

return data["entry"][0]["changes"][0]["field"]

Shouldn't it be:

return data["entry"][0]["changed_fields"][0] ?

Import error

I am getting this error
def get_mobile(self, data) -> (str | None):
TypeError: unsupported operand type(s) for |: 'type' and 'NoneType'

you forgot to import from future import annotations in init_.py file
please do it .I have to submit this project

INFO - Message sent to number but it no longer arrives to WA

Just started testing heyoo/wa yesterday to send me text messages and it worked but today log shows message was sent succesfully but the message never arrived WA.
I had to renew token in Could API (token error was in the log but still message say it was sent succesfully but it wasn't. Even after renewing and using new temporary token it does not work. Sending a message directly from Meta works. Sending a message from heyoo says it was sent but it did not arrive to my WA.

2023-05-24 21:26:53,328 - root - INFO - Sending message to 520000000000
2023-05-24 21:26:54,132 - root - INFO - Message sent to 520000000000

Using Fedora 38, Python 3.10.11, heyoo 0.0.9

Add return types for getter methods

I believe it would ease integration into 3rd party code and improve correctness and error handling in the future. I can open a PR if needed.

Automated tests with pytest

I think the examples folder should be rewritten as tests. This would still serve their purpose for examples but also give test to find potential bugs earlier. I already created a first version what this could look like. The TOKEN, PHONE_NUMBER_ID and RECIPIENT_ID could be put in the github secrets and the tests could be execute after commit on the main branch. For local testing everyone has to provide his/her own environment secrets.

Whatsapp messages cannot be received although no error message pops up as output

Environment:
MACOS Monterey
Python:3.7.3
heyoo:0.0.6 (pip)

Code:
from heyoo import WhatsApp
messenger = WhatsApp('xxx',phone_number_id='xxx')
messenger.send_message('Hello I am WhatsApp Cloud API', '49xxx')

Output:
2022-11-03 22:51:34,464 - root - INFO - Sending message to 49xxx
2022-11-03 22:51:35,200 - root - INFO - Message sent to 49xxx

Description:
Although my Facebook WhatsApp setting are done properly(Test message from Facebook Website can be sent properly). The WhatsApp message cannot be sent via heyoo. (No error message is received from python)

Note:I am sure that my token number, phone_number_id and recipient_id number are correct, with the reason that if I write anything wrong in these fields, I get following error message.:

2022-11-03 23:03:01,945 - root - INFO - Status code: 400
2022-11-03 23:03:01,945 - root - INFO - Response: {'error': {'message': '(#131030) Recipient phone number not in allowed list', 'type': 'OAuthException', 'code': 131030, 'error_data': {'messaging_product': 'whatsapp', 'details': 'Empfänger-Telefonnummer steht nicht auf Positivliste: Füge die Telefonnummer des Empfängers zu einer Empfängerliste hinzu und versuche es dann noch einmal.'}, 'error_subcode': 2655007, 'fbtrace_id': 'Akf6LRk1j9htPAuzA5P971E'}}

get_message for messages of type interactive or list_reply

Hello again,
I think get_message should be renamed to get_message_text (current naming is ambiguous, it is not clear if the function returns the message object or the text). And I would argue it should return the button_reply -> title for messages of type interactive and the list_reply -> title and list_reply -> description for list_reply
What do you think?

recipient phone number not in allowed list

i'm there I just sent a message to my whatsapp test phone number, the message arrives but i can't reply, these are the logs, any help?

'body': 'Hey'}, 'type': 'text'}]}, 'field': 'messages'}]}]}
2023-07-08 12:50:26,145 - root - INFO - New Message; sender: <PHONE> name:<NAME> type:text
2023-07-08 12:50:26,145 - root - INFO - Message: Hey
2023-07-08 12:50:26,145 - root - INFO - Sending message to <PHONE>
2023-07-08 12:50:26,372 - root - INFO - Message not sent to <PHONE>
2023-07-08 12:50:26,372 - root - INFO - Status code: 400
2023-07-08 12:50:26,372 - root - ERROR - Response: {'error': {'message': '(#131030) Recipient phone number not in allowed list', 'type': 'OAuthException', 'code': 131030, 'error_data': {'messaging_product': 'whatsapp', 'details': 'Recipient phone number not in allowed list: Add recipient phone number to recipient list and try again.'}, 'fbtrace_id': <ID>}}

(yeah I masked some variables)

Send Template message with components

I'm trying to send a message template with 2 variables but the message is not being sent. I there any issue with my code? Please help.

messenger.send_template("artist_approve", "91"+instance.phone, components={"type": "body","parameters": [{"type": "text","text": instance.user.first_name+" "+instance.user.last_name},{"type": "text","text": "https://dirums.com/artist-details/"+instance.slug}]})

More arguments for the function to send interactive lists

Hi,
I think it would be easier to add more arguments to the function and not put everything in one dictonary.
The function could look like this;

def send_interactive_list(self, recipient_id, body_text, button_text, sections, header_text=None, footer_text=None):
    interactive_dict = {}
    if header_text:
        interactive_dict["header"] = {"type": "text", "text": header_text}
    if footer_text:
        interactive_dict["footer"] = {"text": footer_text}
    if body_text:
        interactive_dict["body"] = {"text": body_text}

    interactive_dict["type"] = "list"
    interactive_dict["action"] = {}
    interactive_dict["action"]["button"] = button_text

    interactive_dict["action"]["sections"] = sections

    data = {
        "messaging_product": "whatsapp",
        "to": recipient_id,
        "type": "interactive",
        "interactive": interactive_dict,
    }
    logging.info(f"Sending buttons to {recipient_id}")
    r = requests.post(self.url, headers=self.headers, json=data)
    if r.status_code == 200:
        logging.info(f"Buttons sent to {recipient_id}")
        return r.json()
    logging.info(f"Buttons not sent to {recipient_id}")
    logging.info(f"Status code: {r.status_code}")
    logging.info(f"Response: {r.json()}")
    return r.json()

What are your thoughts?

Only one method for sending templates

Hi,
I think there should be only one method for sending templates. Currently there is no clear difference between send_templatev2 and send_template. In my opinion send_templatev2 sould be removed. If someone ist using it they shoud switch to send_template. Or did I miss anything here.

Webhook subscription sending old messages

I was testing the webhook example, everything works fine but I am still receiving old messages. I wonder if this is the normal functioning?

I send a message from my phone (e.i Hi) and then I receive multiple times the message on my webhook:

2022-08-21 10:35:47,046 - root - INFO - New Message; sender:xxxxxxx86 name:Gustavo Gordillo type:text
2022-08-21 10:35:47,257 - werkzeug - INFO - 127.0.0.1 - - [21/Aug/2022 10:35:47] "POST /conversations/webhook HTTP/1.1" 200
2022-08-21 10:35:48,854 - root - INFO - New Message; sender:xxxxxxx86 name:Gustavo Gordillo type:text
2022-08-21 10:35:48,982 - werkzeug - INFO - 127.0.0.1 - - [21/Aug/2022 10:35:48] "POST /conversations/webhook HTTP/1.1" 200
2022-08-21 10:35:50,898 - root - INFO - New Message; sender:xxxxxxx86 name:Gustavo Gordillo type:text
2022-08-21 10:35:51,040 - werkzeug - INFO - 127.0.0.1 - - [21/Aug/2022 10:35:51] "POST /conversations/webhook HTTP/1.1" 200
2022-08-21 10:35:51,514 - root - INFO - New Message; sender:xxxxxxx86 name:Gustavo Gordillo type:text

At the end of the script I am sending a return "ok" (as in the example).

PD: amazing project! :)

Requests Package Missing

Heyoo package requires requests. But the package is missing.

import requests ModuleNotFoundError: No module named 'requests'

I am also available to raise PR's to fix the issues

requests_toolbelt is not listed as a dependency

Hi,
requests_toolbelt is used by not probably defined as a dependency in the setup.py. It is just used in one place.
I think it would be a better approach to remove it to not add too many dependencies. I don't think it is even necessary there.

I would happily create a PR if it is decided which approach (add a dependency or change code) to go with.

Elevate Error of API

Meta in their API has specific code for each type error, you can read this error, code and raise exception that we can catch, to know that is wrong in the send message because the error is silent.

2023-04-24 10:04:53,261 - root - INFO - Image not sent to 50763036683 2023-04-24 10:04:53,261 - root - INFO - Status code: 400 2023-04-24 10:04:53,262 - root - ERROR - {'error': {'message': '(#131030) Recipient phone number not in allowed list', 'type': 'OAuthException', 'code': 131030, 'error_data': {'messaging_product': 'whatsapp', 'details': 'El número de teléfono del destinatario no está en la lista de autorizados: Agrega el número de teléfono del destinatario a la lista de destinatarios y vuelve a intentarlo.'}, 'fbtrace_id': 'A4yeLb3JmDl2ZvQMvBgCANu'}}

ObjectIdException

	"error": {
		"message": "Unsupported post request. Object with ID '118130101241809' does not exist, cannot be loaded due to missing permissions, or does not support this operation. Please read the Graph API documentation at https:\/\/developers.facebook.com\/docs\/graph-api",
		"type": "GraphMethodException",
		"code": 100,
		"error_subcode": 33,
		"fbtrace_id": "A2H9tBUK0RHUB91NwUjrY23"
	}
}

RecipientPhoneNumberException

	"error": {
		"message": "(#131030) Recipient phone number not in allowed list",
		"type": "OAuthException",
		"code": 131030,
		"error_data": {
			"messaging_product": "whatsapp",
			"details": "El número de teléfono del destinatario no está en la lista de autorizados: Agrega el número de teléfono del destinatario a la lista de destinatarios y vuelve a intentarlo."
		},
		"fbtrace_id": "AguKtar08vzPr310wo-jcjY"
	}
} 

webhook got data even if the user didnt send a msg

hi,
I am writing in python a webhook to use in my meta whatsapp app.
The webhook is called even if the user didnt send any messages. (It prints "Received webhook data" from the code below and continue).
What do I need to change in this code to make sure the webhook really got a message and not some other request from whatsapp? which condition do I need to check in the request\data and do return if its not a real message? or change somthing in the changed_field condition?
Thank you

@app.route("/", methods=["GET", "POST"])
def hook():
code...
code...
# Handle Webhook Subscriptions
data = request.get_json()
logging.info("Received webhook data: %s", data)
changed_field = messenger.changed_field(data)
if changed_field == "messages":

where changed_field is:
return data["entry"][0]["changes"][0]["field"]
...
...

Can messages send to groups?

Is it possible to send messages to a group via the api? Instead of using the recipient_id using the group_id?

Send reply button only displays three reply buttons.

Hello,

I've been using the library for a while and I would like to communicate this information to anyone who's going to use it (Perhaps this could be included in the documentation of the functions):

The function "send_reply_button" should say that it only shows 3 reply buttons. If more are posted then no reply buttons will appear.

"""
        Send a message with a maximum of three reply buttons beneath it.
        :param button: Button object, check https://github.com/Neurotech-HQ/heyoo#sending-interactive-reply-buttons
        for an example.
        :param recipient_id: Typically the phone number of the recipient
        :return:
"""

importing Heyoo is messing logging configuration

heyoo messes up logging init and it needs to be placed after basicConfig statement as fol;owing:

from flask_executor import Executor

LOG_FILE_NAME = "service.log"
logging.basicConfig(
level=logging.DEBUG,
filename=LOG_FILE_NAME,
filemode="a+",
format="%(asctime)-15s %(levelname)-8s %(message)s",
)

// Unfortunately heyoo messes up logging init, needs to be placed after basicConfig statement
from heyoo import
WhatsApp # pylint: disable=wrong-import-position, wrong-import-order

Looping old messages ( I am Building a chatbot for Whatsapp)

if i re deploy the bot on heruku, it's looping through the old messages and spamming.
PLS HELP TO FIX IT!'

HEREUKU LOGS!
image

if request.method == 'POST':
body = request.getjson()
print(body)
if body.get("object") and body.get("entry") and body["entry"][0].get("changes") and
body["entry"][0]["changes"][0].get("value").get("messages"):
from = body["entry"][0]["changes"][0]["value"]["messages"][0]["from"]
msg_id = body["entry"][0]["changes"][0]["value"]["messages"][0]["id"]
datetime_str = body["entry"][0]["changes"][0]["value"]["messages"][0]["timestamp"]
msgbody = body["entry"][0]["changes"][0]["value"]["messages"][0].get("text", {}).get("body", "")
name = body["entry"][0]["changes"][0]["value"]["contacts"][0]["profile"]["name"]

error invalid access token

{'error': {'message': 'Invalid OAuth access token - Cannot parse access token', 'type': 'OAuthException', 'code': 190, 'fbtrace_id':

help me please

Sent Messages Undelivered

image

I have Flask webhook from the project folder running on port 5000 and I get 200 OK responses but I don't receive the messages, what am I missing here?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.