https://tawked.com/v1/....
This page is the whole integration: making your app, the Connect flow, a worked example of creating a template and sending it, adding a conversation menu beside the customer’s conversations in Tawked Chat, setting up the customer’s auto-attendant, the rules your credential meets, and how access ends.
The customer keeps the account, the number, the balance and the last word: they see what your app sent and the templates it made, and they can disconnect it at any time.
Before you start
You make your app yourself, in the Tawked console. It takes a partner account: its owner, or an admin whose access covers every application, finds Integration apps in the console’s sidebar. A platform that is not a partner yet writes to Tawked to become one. 1. Make the app. On Integration apps, press New app and give:- your app’s name, in Arabic and in English, as customers will read it on Tawked’s page. A name that contains “Tawked” is refused;
- your website’s address;
- the exact return address or addresses of your Connect flow (
redirect_uri), https only, five at most; - the address of the page in your product where a customer presses Connect. It is optional;
- a square logo, PNG or JPG. It is optional: without one Tawked shows the first letter of your app’s name;
- what your app does, in a few lines for Tawked’s reviewer. Customers never read it, and it can wait until you send the app for review.
- a client id, which is public and always shown there;
- a client secret, shown once, when the app is made. Keep it on your server only. If you lose it, press Renew the secret on the same page: the new one is shown once, and the old one stops at once.
The flow
1
Send the customer to Tawked
When the customer presses Connect, make a random
state and a PKCE code_verifier, keep both in their session, and send the browser to:redirect_uri is one of the return addresses you gave for your app, exactly, and it is https. PKCE is required: a request without code_challenge is refused, code_challenge_method is S256, and plain is refused. Send no scope: the permissions are the same for every app.Tie state to the signed-in user of your own product, in their browser session. It is what keeps one customer’s approval from landing in another customer’s account with you.2
The customer answers on Tawked's page
The customer signs in to Tawked if they are not signed in, and comes back to the same page. It names your app, lists what it may do (for the menus: “Add tabs beside your conversations, and change or remove the ones it added”; for the auto-attendant: “Set up your auto-attendant, publish it, and switch it on or off”), and offers the applications that can be connected: the customer’s own applications that have a connected WhatsApp number. The customer picks one, then allows or refuses.Whoever manages the application’s API keys may approve. When the person who pressed Connect may not, Tawked sends the request on to the people who may, and the page says so. Once one of them has allowed it in Tawked, the customer presses Connect in your product again: Tawked’s page says the request was allowed, and one button brings them back to you with the code. Only the person who opened the request, or the one who allowed it, takes it back. Another member of the customer’s account who presses Connect starts a new request. A request that nobody answers runs out after 7 days.
3
Read the return
The browser comes back to your
redirect_uri:Check that
state is the one you made for this user’s session before you do anything else, and refuse a return whose state you did not issue.4
Exchange the code on your server
Cache-Control: no-store. access_token is the credential for that one application. There is no refresh token, and the credential does not expire with time. Store it like a password, encrypted, next to connection_id and the customer it belongs to; Tawked never shows it again.5
Call the API
Send the credential as a Bearer key, exactly as any application key is sent:The next section walks through a template and a send.
A worked example: create a template, then send it
Every message is an approved template, and your app sends utility templates only. Create one for the customer’s number, wait for Meta to approve it, then send it. 1. Create the template. The body’s placeholders are named, andexamples gives one sample value per placeholder, keyed body:<key>: Meta reviews with them.
201. id is Meta’s id of this language of the template; keep it. The fields:
A field that breaks a rule answers
400 invalid_request: fields names every refused field and errors gives each one’s reason codes. For the sample: headerSampleMissing, headerSampleUnreachable (not https, a private address, an error status, a timeout), headerSampleInvalid (not a PDF, or not a JPG or PNG) and headerSampleTooLarge; for an unknown header_format, headerFormatInvalid. The sample is only for Meta’s review: each message carries its own file in header.image or header.document when it is sent, as in Send a PDF attachment. What Meta refuses after that answers 422 template_refused, with Meta’s own sentence in message.
2. Wait for Meta’s review. Read the template until its status is APPROVED. A REJECTED one carries Meta’s reason in rejected_reason.
params carries one value per placeholder, by name. to is a Saudi mobile number.
202. A template Meta has not approved yet answers 422 template_not_approved. Sending the same Idempotency-Key again answers the same 202 with Idempotent-Replayed: true and sends nothing.
4. Read the status. GET https://tawked.com/v1/whatsapp/messages/{id} with the id of the send answers the message with its status: accepted, then sent, delivered, read, or failed with Meta’s error.
Replies are the customer’s. When a recipient answers a message your app sent, the reply arrives in the customer’s own Tawked Chat inbox, where the customer’s team answers it. Your app does not receive replies.
Marketing templates are not open to connected apps. Your credential creates and sends utility templates only.
Add a conversation menu for your client
A conversation menu is a page of yours that Tawked Chat shows as a tab beside the conversations of the connected application’s WhatsApp number, with the open customer filled into its link. With your credential you add it yourself, so the customer does nothing: once you add it, their team sees the tab after reloading Tawked Chat. 1. Make a key for this one customer. The menu’s link carries a key that tells your server the request came through this customer’s menu. Make a different key for each customer, for example withopenssl rand -hex 32, and keep a mapping from key to customer on your server, so that the page shows only that customer’s data. Never put your Tawked credential or your client secret in the link: the customer’s team can read it.
2. Add the menu.
201. Keep id. The fields of the menu:
icon is "site" (the default: Tawked takes your site’s own icon, its favicon or apple-touch-icon, as the console does), "none", or { "url": "https://.../icon.png" }: an https link to a PNG, JPEG or WebP of at most 1 MB and at least 32 px on its short side, which Tawked downloads once from a public address and turns into the 64 px icon.
Find the customer. Your page receives the customer’s phone from the conversation, in international format (+966551234567), through {customer_phone} in the link or the page script. Look the customer up by it within the business the key names, with both sides brought to the same digits: see Find the customer in your system.
3. Read, change or remove it.
You see only the menus your connection made, never the customer’s own or another app’s, whose links may hold their keys: any other id answers
404 not_found. The writes take an optional Idempotency-Key, with the same rules as the template writes.
Rotate a customer’s key with PATCH: add the new key on your server beside the old one, send the new link, and drop the old key once the customer’s team has reloaded Tawked Chat.
What the customer sees. Your menus appear in the customer’s list of menus in the Tawked console, marked with your app’s name, and the customer may still edit or delete them. Every write of yours is recorded in the customer’s account under your app’s name.
The errors. After the checks every call shares (
401 unauthorized, 403 insufficient_scope naming chat:menus, 403 account_not_active, 403 live_key_required):
A business’s own key, full access included, answers these five calls
403 insufficient_scope: a business adds its own menus in the console.
When the connection ends, because the customer disconnects your app or revokes its key, the menus that connection made are removed from Tawked Chat.
Set up the auto-attendant for your client
The auto-attendant («المجيب الآلي») answers a new conversation on the connected application’s WhatsApp number in Tawked Chat with a menu of tappable choices: an opening message and up to 10 choices, each doing one thing. With your credential you build it, publish it and switch it on yourself, so the customer does nothing. An application has one auto-attendant, the same one the customer builds on Chat → Auto-attendant in the console. Each choice does one of five things:
A menu of 1 to 3 choices shows as reply buttons; 4 to 10 show as a list behind a button.
1. Save the draft. The draft reaches no customer. This is a sports academy’s menu: five choices, so a list, every one a reply but the last, which hands the customer to the academy’s team.
200 with the menu as stored: every choice with its id, every field the menu may hold, and every assign as { "mode": "auto", "member_id": null }. A choice you send without an id gets one; send your own (c_ then 4 to 12 lowercase letters or digits) to keep them stable from one save to the next. Saving replaces the whole draft. The console and the API share this one draft, and the last save wins: read it with GET before you change a menu the customer may have edited.
2. Check problems. A draft may hold problems; a publish refuses them. problems is [] here. Each problem is { "code", "choice_id", "field", "max" }: choice_id is null for the top level, and max is the limit crossed, or null.
3. Publish it. The call takes no body.
{ "enabled": false } switches it off, and the conversations it holds go to the team.
5. Read it. GET https://tawked.com/v1/chat/attendant now answers "state": "live":
الاشتراكات; the team; and Radeef. Three choices, so buttons.
The menu:
The action’s fields:
reply takes text (up to 1024) and link (an https link up to 2048, or null); submenu takes text (its message, up to 1024) and choices; ask takes detail, label (for custom only, up to 24), question (up to 1024), tag and assign; team takes line (up to 1024, or null), tag and assign; radeef takes nothing more. tag is the label the conversation gets in Tawked Chat. assign is { "mode": "auto" }: Tawked Chat assigns the conversation as usual; a named member is set in the console.
The calls:
The four writes take an optional
Idempotency-Key, with the same rules as the template writes.
The rules are the console’s own:
The problems a draft may hold and a publish refuses:
What the customer sees. The customer sees the same auto-attendant in the console, and may change it there. Every publish, switch and settings change of yours is recorded in the customer’s account under your app’s name; draft saves are not, as in the console. The auto-attendant’s replies are free on Tawked; Meta’s own rules for replies inside the customer service window apply, see Free replies.
The errors. After the checks every call shares (
401 unauthorized, 403 insufficient_scope naming chat:attendant, 403 account_not_active, 403 live_key_required):
A business’s own key, full access included, answers these five calls
403 insufficient_scope: a business builds its auto-attendant in the console.
When the connection ends, the auto-attendant stays as it is: it is the customer’s, and the customer turns it off in the console.
When the exchange is refused
The exchange answers OAuth’s own errors, as{ "error", "error_description" }:
After a refused exchange, send the customer through Connect again: an approval that is still waiting gives a new code without a second question.
What your credential may do
It reaches Tawked Notifications for that one application, within your app’s permissions: it sends template messages, reads the messages it sent, lists and reads the templates, and creates, edits and deletes templates. In Tawked Chat it adds, reads, changes and removes the conversation menus it made, and builds, publishes and switches the application’s auto-attendant. Creating, editing and deleting a template over the API is a connected app’s alone. A business’s own key, full access included, answers those three calls403 insufficient_scope: the business writes its templates in the Tawked console. Your credential holds notifications:templates, as every connected app’s does.
Every path is under
https://tawked.com.
The writes take templates that open with text, an image or a document, or with no header (no video or location header, no authentication template), and an optional Idempotency-Key. PATCH takes the whole new content, the body of a creation without name and language, header_format included: the edit of a template that opens with an image or a document answers 409 template_not_editable with MEDIA_HEADER without it, so an edit written for text never drops the file, and an edit without header_sample_url keeps the sample Meta holds. Only an APPROVED, REJECTED or PAUSED template is edited; anything else answers 409 template_not_editable with a status that says why, MEDIA_HEADER for a template that opens with a video or a location. DELETE answers { "id", "name", "language", "deleted": true }.
Your credential also meets rules of its own:
Messages are charged to the customer’s balance and sent from the customer’s number, like any message of that application. The customer sees every template your app made and every message it sent.
When access ends
Access ends when the customer disconnects your app in Tawked, or revokes its key, and while Tawked has stopped your app. From then on every call answers401 unauthorized. When the connection ends, the conversation menus it made are removed from Tawked Chat; the auto-attendant stays as it is, the customer’s to turn off. Treat that answer as “not connected”: stop sending for that customer and show Connect again.
Connecting the same application again issues a new credential and retires the old one, on the same connection_id. Replace what you stored.
More than one application
A credential is for one application. A customer with a second application presses Connect again and chooses it: you receive a second credential and a secondconnection_id, and the first keeps working.
Checklist
- Keep the client secret and every credential on your server, never in a browser or a mobile app.
- Bind
stateto your user’s session and check it on every return. - Store one credential per
connection_id, encrypted. - Send an
Idempotency-Keyon every send, every template write, every menu write and every auto-attendant write. - Give each customer’s menu its own key, never your credential or client secret.
- Match errors on the
errorstring. The Errors page lists every code. - On
401 unauthorized, mark the customer as disconnected.