Skip to content

Commit 89405f6

Browse files
dkstevekwakanujs3
andauthored
Add Threads Webhooks in the sample app (#33)
* add Threads support * add Threads support * add Threads support * init * Update heroku/README.md Co-authored-by: Anuj Shah <[email protected]> --------- Co-authored-by: Anuj Shah <[email protected]>
1 parent 109af68 commit 89405f6

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Graph API Webhooks Samples
22

3-
These are sample clients for Facebook's [Webhooks](https://developers.facebook.com/docs/graph-api/webhooks/) product and Instagram's [Subscriptions API](https://www.instagram.com/developer/subscriptions/).
3+
These are sample clients for Facebook's [Webhooks](https://developers.facebook.com/docs/graph-api/webhooks/) product, Instagram's [Subscriptions API](https://www.instagram.com/developer/subscriptions/), and Threads' [Webhooks](https://developers.facebook.com/docs/threads/webhooks).
44

55
1. [Heroku](heroku) - A sample client that receives Webhook events.
66
1. [Hubot](hubot) - A script that messages a chat room when a Facebook Page post is published using Webhooks.

heroku/README.md

+9-2
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,19 @@ This is a sample client for Facebook's [Webhooks](https://developers.facebook.co
99
1. Refer to Facebook's [Webhooks sample app documentation](https://developers.facebook.com/docs/graph-api/webhooks/sample-apps) to see how to use this app.
1010
1. Deploy the sample app on Heroku with this button:
1111

12-
[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/fbsamples/graph-api-webhooks-samples)
12+
[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/fbsamples/graph-api-webhooks-samples/)
1313

1414
### Instagram Subscription API
1515
1. Register an [Instagram API client](https://instagram.com/developer/clients/manage/).
1616
1. Deploy the sample app on Heroku with this button:
1717

18-
[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/fbsamples/graph-api-webhooks-samples)
18+
[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/fbsamples/graph-api-webhooks-samples/)
1919

2020
1. Set up your client's [subscription](https://www.instagram.com/developer/subscriptions/) using your `https://<your-subdomain>.herokuapp.com/instagram` as the callback URL. It is recommended that you set a `TOKEN` [config var](https://devcenter.heroku.com/articles/config-vars) as part of the set up of your Heroku app to secure requests. If you choose not to set a config var, then you will need to set a verify token of 'token' when configuring the callback URL.
21+
22+
### Threads Webhooks
23+
1. Deploy the sample app on Heroku with this button:
24+
25+
[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/fbsamples/graph-api-webhooks-samples/)
26+
27+
1. Refer to [Threads' Webhooks Documentation](https://developers.facebook.com/docs/threads/webhooks) and set up Threads Webhooks product as a sub use case under the Threads API main use case. Also, set up your webhooks callback URL as `https://<your-subdomain>.herokuapp.com/threads`. It is recommended that you set a `TOKEN` [config var](https://devcenter.heroku.com/articles/config-vars) as part of the set up of your Heroku app to secure requests. If you choose not to set a config var, then you will need to set a verify token of 'token' when configuring the callback URL.

heroku/index.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ app.get('/', function(req, res) {
2525
res.send('<pre>' + JSON.stringify(received_updates, null, 2) + '</pre>');
2626
});
2727

28-
app.get(['/facebook', '/instagram'], function(req, res) {
28+
app.get(['/facebook', '/instagram', '/threads'], function(req, res) {
2929
if (
3030
req.query['hub.mode'] == 'subscribe' &&
3131
req.query['hub.verify_token'] == token
@@ -59,4 +59,12 @@ app.post('/instagram', function(req, res) {
5959
res.sendStatus(200);
6060
});
6161

62+
app.post('/threads', function(req, res) {
63+
console.log('Threads request body:');
64+
console.log(req.body);
65+
// Process the Threads updates here
66+
received_updates.unshift(req.body);
67+
res.sendStatus(200);
68+
});
69+
6270
app.listen();

0 commit comments

Comments
 (0)