A customer sends your business number "What is your return policy?", and the agent answers in the same WhatsApp chat. The whatsapp connector does this with your own Meta app.
Answer on WhatsApp
You need five things from Meta: your app's ID and App Secret, your number's phone number ID, its WhatsApp account ID, and an access token. We recommend starting with Meta's test number. Setup takes six steps:
Create a Meta app
At developers.facebook.com, create an app with the use case Connect with customers through WhatsApp. The App ID and App Secret are under App settings > Basic. Under Use cases > Customize > Step 1. Try it out, copy the test number's Phone Number ID and Messaging account ID, and add your own phone as a Recipient.
Create a token that doesn't expire
At business.facebook.com, open Settings > Users > System users and add an Admin system user. Give it full control of your app and your WhatsApp account, then choose Generate token with Never as the expiration and the whatsapp_business_messaging and whatsapp_business_management permissions.
Save your Meta app
Give Stream the App ID and the App Secret:
curl -fsSL https://getstream.io/cli.sh | bash # get the CLI
echo "$META_APP_SECRET" | getstream agents connectors client set whatsapp --provider-app-id "$META_APP_ID" --signing-secret -The CLI prints Saved the provider app for whatsapp.
Connect the number
Create the connection with the phone number ID and the access token:
echo "$WHATSAPP_ACCESS_TOKEN" | getstream agents connections create whatsapp --label acme-whatsapp --input phone_number_id=$PHONE_NUMBER_ID -H Authorization=-The CLI prints Connected: whatsapp / acme-whatsapp, with the connection's id.
Point Meta at Stream
Do it after steps 3 and 4: Meta checks the URL at once.
The verify token is your Meta app ID, and $WABA_ID is the Messaging account ID:
curl -X POST "https://graph.facebook.com/v25.0/$META_APP_ID/subscriptions" \
--data-urlencode "access_token=$META_APP_ID|$META_APP_SECRET" \
--data-urlencode "object=whatsapp_business_account" \
--data-urlencode "callback_url=$STREAM_ACCELERATION_URL/v1/connectors/events/whatsapp/$META_APP_ID" \
--data-urlencode "verify_token=$META_APP_ID" \
--data-urlencode "fields=messages"
curl -X POST "https://graph.facebook.com/v25.0/$WABA_ID/subscribed_apps" \
-H "Authorization: Bearer $WHATSAPP_ACCESS_TOKEN"Both answer {"success": true}.
Add it to the agent
If you don't have an agent named support yet, create one in Creating an agent. Add the connection by its label:
getstream agents connectors bind support whatsapp --connection acme-whatsappThe command adds this to agents/support/agent.yaml and syncs the agent. See a full agent.yaml for the rest of the file.
# ...
connectors:
- name: whatsapp
connection: acme-whatsappYou can't start a chat with a test number from your phone, so send yourself Meta's hello_world first. Reply "What is your return policy?" in that chat, and the agent's answer comes back in the same chat.
Say hello from a test number
Put your own phone in to:
curl -X POST "https://graph.facebook.com/v25.0/$PHONE_NUMBER_ID/messages" \
-H "Authorization: Bearer $WHATSAPP_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{"messaging_product": "whatsapp", "to": "+12025550100", "type": "template", "template": {"name": "hello_world", "language": {"code": "en_US"}}}'Send a photo
A photo reaches the agent. Send a photo with "What is in this photo?", and the agent answers about the photo. A photo with no caption works too.
If photos do not reach the agent, save the token again. On the connection's page, choose Replace token and enter the access token again.
Keywords
Stream handles these, not the agent:
- HELP: Stream answers "Reply STOP to unsubscribe."
- STOP: the person is opted out. Stream answers "You are unsubscribed and will receive no more messages. Reply START to resubscribe.", and the agent answers nothing more from them until they send START.
- START: the person is opted back in. Stream answers "You are subscribed again. Reply STOP to unsubscribe."
Limitations
The agent replies only within 24 hours of the person's last message.
When a message gets no answer
| What you see | Why | What to do |
|---|---|---|
| WhatsApp says your test number is not on WhatsApp | A test number can't be found in a search | Send yourself hello_world |
Meta answers (#133010) Account not registered |
The number isn't registered with Meta's API yet | Register it, as below |
| A person gets no reply after STOP | The person opted out | The person sends START |
To register a number, pick a six-digit PIN and keep it. It becomes the number's two-step verification PIN:
curl -X POST "https://graph.facebook.com/v25.0/$PHONE_NUMBER_ID/register" \
-H "Authorization: Bearer $WHATSAPP_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{"messaging_product": "whatsapp", "pin": "<six digits>"}'