You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: recipes/use_cases/chatbots/messenger_llama/messenger_llama3.md
+12-14Lines changed: 12 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,11 +10,11 @@ Messenger from Meta is a messaging service that allows a Facebook business page
10
10
11
11
The diagram below shows the components and overall data flow of the Llama 3 enabled Messenger chatbot demo we built, using an Amazon EC2 instance as an example for running the web server.
1. A Facebook Page is required to send and receive messages using the Messenger Platform - see [here](https://www.facebook.com/business/help/461775097570076?id=939256796236247) for details about Facebook Pages and how to create a new page.
17
+
1. A Facebook Page is required to send and receive messages using the Messenger Platform - see [here](https://www.facebook.com/business/help/461775097570076?id=939256796236247) for details about Facebook Pages and how to create a new page.
18
18
19
19
2. If you have followed the [Llama WhatsApp chatbot tutorial](../whatsapp_llama/whatsapp_llama3.md), or if you already have a Meta developer account and a business app, then you can skip this step. Otherwise, you need to first [create a Meta developer account](https://developers.facebook.com/) and then [create a business app](https://developers.facebook.com/docs/development/create-an-app/).
20
20
@@ -24,7 +24,7 @@ The diagram below shows the components and overall data flow of the Llama 3 enab
24
24
25
25
5. Open Messenger's API Settings, as shown in the screenshot below, then in "1. Configure webhooks", set the Callback URL and Verify Token set up in the previous step, and subscribe all message related fields for "Webhook Fields". Finally, in "2. Generate access tokens", connect your Facebook page (see step 1) and copy your page access token for later use.
Replace <page_access_token> with the access token copied in step 5 "Open Messenger's API Settings" of the previous section. Now it's time to modify the webhook to complete the whole app.
91
91
92
-
## Modifying the Webhook
92
+
## Modifying the Webhook
93
93
94
94
Open your glitch.com webhook URL created earlier, and change your `app.js` to simply forward the user message and the user and page ids sent by the Messenger Platform to the Llama 3 enabled web app `llama_messenger.py` described in the previous section:
// Return a '404 Not Found' if event is not from a page subscription
137
137
res.sendStatus(404);
138
138
}
139
139
});
140
140
141
141
// Accepts GET requests at the /webhook endpoint. You need this URL to setup webhook initially.
142
-
// info on verification request payload: https://developers.facebook.com/docs/graph-api/webhooks/getting-started#verification-requests
142
+
// info on verification request payload: https://developers.facebook.com/docs/graph-api/webhooks/getting-started#verification-requests
143
143
app.get("/webhook", (req, res) => {
144
144
/**
145
145
* UPDATE YOUR VERIFY TOKEN
@@ -179,7 +179,7 @@ On your web server, run the following command on a Terminal (see [here](https://
179
179
gunicorn -b 0.0.0.0:5000 llama_messenger:app
180
180
```
181
181
182
-
If you use Amazon EC2 as your web server, make sure you have port 5000 added to your EC2 instance's security group's inbound rules.
182
+
If you use Amazon EC2 as your web server, make sure you have port 5000 added to your EC2 instance's security group's inbound rules.
183
183
184
184
Now you can open your Messenger app, select the Facebook page you connected in Messenger's API Settings, enter a message and receive the Llama 3's answer shortly, as shown in the demo video in the beginning of this post.
185
185
@@ -190,5 +190,3 @@ http://<web server public IP>:5000/msgrcvd_page?sender=<user id>&recipient=<page
190
190
```
191
191
192
192
Then open the URL in a browser to verify your web server can receive the message and the two ids, and generate a Llama answer before sending the answer back to Messenger.
Copy file name to clipboardExpand all lines: recipes/use_cases/chatbots/whatsapp_llama/whatsapp_llama3.md
+15-15Lines changed: 15 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,7 @@ Businesses of all sizes can use the [WhatsApp Business API](https://developers.f
10
10
11
11
The diagram below shows the components and overall data flow of the Llama 3 enabled WhatsApp chatbot demo we built, using Amazon EC2 instance as an example for running the web server.
## Getting Started with WhatsApp Business Cloud API
16
16
@@ -19,13 +19,13 @@ First, open the [WhatsApp Business Platform Cloud API Get Started Guide](https:/
19
19
1. Add the WhatsApp product to your business app;
20
20
2. Add a recipient number;
21
21
3. Send a test message;
22
-
4. Configure a webhook to receive real time HTTP notifications.
22
+
4. Configure a webhook to receive real time HTTP notifications.
23
23
24
24
For the last step, you need to further follow the [Sample Callback URL for Webhooks Testing Guide](https://developers.facebook.com/docs/whatsapp/sample-app-endpoints) to create a free account on glitch.com to get your webhook's callback URL.
25
25
26
-
Now open the [Meta for Develops Apps](https://developers.facebook.com/apps/) page and select the WhatsApp business app and you should be able to copy the curl command (as shown in the App Dashboard - WhatsApp - API Setup - Step 2 below) and run the command on a Terminal to send a test message to your WhatsApp.
26
+
Now open the [Meta for Develops Apps](https://developers.facebook.com/apps/) page and select the WhatsApp business app and you should be able to copy the curl command (as shown in the App Dashboard - WhatsApp - API Setup - Step 2 below) and run the command on a Terminal to send a test message to your WhatsApp.
add the code below - remember to change <webserverpublicIP>, which needs to be publicly visible, to the IP of the server where your Llama 3 enabled web app in the previous section runs:
123
123
124
124
```
125
-
let url = "http://<web server public IP>:5000/msgrcvd?message=" +
125
+
let url = "http://<web server public IP>:5000/msgrcvd?message=" +
@@ -140,7 +140,7 @@ The code simply forwards the user message received by the WhatsApp Cloud Platfor
140
140
'// info on WhatsApp text message payload: https://developers.facebook.com/docs/whatsapp/cloud-api/webhooks/payload-examples#text-messages
141
141
if (req.body.object) {
142
142
...
143
-
}
143
+
}
144
144
```
145
145
146
146
Note: It's possible and even recommended to implement a webhook in Python and call Llama 3 directly inside the webhook, instead of making an HTTP request, as the JavaScript code above does, to a Python app which calls Llama 3 and sends the answer to WhatsApp.
@@ -153,10 +153,10 @@ On your web server, run the following command on a Terminal:
153
153
gunicorn -b 0.0.0.0:5000 llama_chatbot:app
154
154
```
155
155
156
-
If you use Amazon EC2 as your web server, make sure you have port 5000 added to your EC2 instance's security group's inbound rules. Write down your web server's public IP, update the URL below with it, then open the URL in a browser to verify you can see the answer sent to your WhatsApp app, as well as shown in the browser:
156
+
If you use Amazon EC2 as your web server, make sure you have port 5000 added to your EC2 instance's security group's inbound rules. Write down your web server's public IP, update the URL below with it, then open the URL in a browser to verify you can see the answer sent to your WhatsApp app, as well as shown in the browser:
157
157
158
158
```
159
159
http://<web server public IP>:5000/msgrcvd?message=who%20wrote%20the%20book%20godfather
160
160
```
161
161
162
-
Now you can open your WhatsApp app, enter a question and receive the Llama 3's answer shortly, as shown in the demo video in the beginning of this post.
162
+
Now you can open your WhatsApp app, enter a question and receive the Llama 3's answer shortly, as shown in the demo video in the beginning of this post.
0 commit comments