Skip to content

whatsapp

WhatsApp: people talk to their agents from WhatsApp, through Meta's Cloud API.

On this page 7
TypeScript
import { whatsapp } from "copilotz/plugins/interfaces";

What it keeps

It keeps 9 collections, 3 of them on the record.

CollectionKept asFields
whatsapp_blockeddocumentsnumber, at
whatsapp_codedocumentsnumber, code, person, expires, at
whatsapp_numberdocumentsin, phoneId, phone, name, url, by, problem, open, agent, gap, rate, quiet, language, declared, at
whatsapp_phonedocumentsnumber, phone, name, person, linked, space, thread, contact, told, tries, since, at
whatsapp_ratein memory, gone on restartminute, count
whatsapp_secretdocumentstoken, secret, verify; private: secret, token, verify
whatsapp_sentrecords, appended and never changedmessage, thread, key, wamid, at
whatsapp_threaddocumentsnumber, phone, person, contact, at
whatsapp_typingin memory, gone on restartnumber, wamid, at, shown

The access rules cover whatsapp_number: each document is in a space, and only those who reach the space reach it.

What it lets callers do

Of its 11 Actions, people may call 9; agents, contacts and someone signed out may call none.

ActionPersonAgentContactAnyoneKeyRoutineWhat it does
whatsapp.blockyesnononononoBlocks the phone behind a WhatsApp chat, or lets it in again.
whatsapp.connectyesnononononoConnects a WhatsApp Business number to a space you manage.
whatsapp.credentialsyesnononononoReplaces a connected WhatsApp number's access token or app secret.
whatsapp.disconnectyesnononononoDisconnects a WhatsApp number from its space.
whatsapp.linkyesnononononoA code to send a WhatsApp number from your phone, to link it to you.
whatsapp.moveyesnononononoWhere your messages from WhatsApp go: a space you may write in.
whatsapp.setyesnononononoOpens a WhatsApp number to anyone (a customer line), or closes it.
whatsapp.unlinkyesnononononoUnlinks your phone from a WhatsApp number.
whatsapp.webhookyesnononononoWhere a WhatsApp number's webhook is, and its verify token, for Meta's dashboard.

An agent works for a person, and calls what both may. A key calls only what its scope names. A routine is work done for a person, which they set going.

Only the app's own code calls whatsapp.number and whatsapp.receive: its plugins, its schedules and the system.

It answers 1 route over HTTP:

MethodPath
GET, POST/hooks/whatsapp/*

It also adds rules every read and write keeps to (guard).

Where it shows

Its Views show elsewhere.

What it needs

You set it in resources.whatsapp: 5 settings are required, and 2 are secrets, kept out of your code.

SettingTypeRequiredWhat it is
whatsapp.<name>.instringyesThe space its customers' chats live in: one the app declares too (the spaces plugin's spaces resource) is made and kept with the number.
whatsapp.<name>.phoneIdstringyesMeta's id for the number, its access token, and the Meta app's secret (signing its webhook).
whatsapp.<name>.tokenstringyesSecret. Meta's id for the number, its access token, and the Meta app's secret (signing its webhook).
whatsapp.<name>.secretstringyesSecret. Meta's id for the number, its access token, and the Meta app's secret (signing its webhook).
whatsapp.<name>.verifystringyesWhat Meta shows to check its webhook, the app's own.
whatsapp.<name>.pathstringnoWhere its webhook is: /hooks/whatsapp/<name> unless the app routes another path to the plugin's hookRoute (its routes field).
whatsapp.<name>.agentstringnoWho answers its customers; a quiet chat's hours; messages a minute; seconds a burst may go on before the answer; customers' language.
whatsapp.<name>.gapnumbernoWho answers its customers; a quiet chat's hours; messages a minute; seconds a burst may go on before the answer; customers' language.
whatsapp.<name>.ratenumbernoWho answers its customers; a quiet chat's hours; messages a minute; seconds a burst may go on before the answer; customers' language.
whatsapp.<name>.quietnumbernoWho answers its customers; a quiet chat's hours; messages a minute; seconds a burst may go on before the answer; customers' language.
whatsapp.<name>.language`"en" \"pt"`noWho answers its customers; a quiet chat's hours; messages a minute; seconds a burst may go on before the answer; customers' language.
whatsapp.<name>.phonestringnoThe number as people dial it, and the business's name, as shown.
whatsapp.<name>.namestringnoThe number as people dial it, and the business's name, as shown.

It also reads additions, links and spaces, resource kinds the app and other plugins fill.

What it requires

The runtime doesn't start without chat, spaces and contacts: add them too.

It ships with copilotz@1.0.0-rc.34.

What it does on its own

Some of its work starts without a caller: an event, or the time.

  • whatsapp.forget runs on contact.deleted.
  • whatsapp.receive runs on whatsapp.received.
  • whatsapp.reply runs on message.created.
  • whatsapp.typing runs on message.created.
  • whatsapp.undelivered runs on whatsapp.undelivered.
  • It emits whatsapp.received. Someone sent a connected WhatsApp number a message.
  • It emits whatsapp.undelivered. A message a connected WhatsApp number sent wasn't delivered.

Listing

It breaks 1 listing rule as it is:

  • Route "/hooks/whatsapp/*" isn't under /whatsapp.