Text flows
A Text flow answers inbound Texts to a number with your code, as a Call flow answers calls. It's one function per Text, not a conversation that resumes, so what it remembers is yours to keep.
export const support = defineTextFlow('support', { numbers: ['+12025550142'] }).onText(
(text, c) => {
if (text.possibleOptOut) return c.optOut();
if (/invoice/i.test(text.body ?? '')) return c.queue('billing');
return c.assign('rep_123');
},
);| Return | What happens |
|---|---|
c.assign(repId) | That Rep owns the Thread, and their desk hears it. |
c.queue(queue) | Labels an unowned Thread with the queue's name for your reps to pick up. Nothing routes it. |
c.reply(body) | We send it from the number that was texted, once per Text. |
c.optOut() | Revokes every scope and adds the number to Do Not Call. |
| Nothing | The Thread goes where it would have gone anyway. |
A keyword never reaches a Text flow. A Text flow that keeps failing, or assigns a Rep we don't know or who is disabled, leaves the Thread as it was.
Add hosting: 'hcc' to a Text flow's options to have us run it. See Hosting.
hcc deploy or hcc.textFlows.deploy makes them take Texts. hcc.serve only warns about one that isn't deployed. On a live hcc deploy, numbers binds them too, which takes numbers:write. A deploy never unbinds a number. To bind by hand: hcc.numbers.update(id, { textFlow: 'support' }), or null to unbind. In test, a Text runs the only Text flow deployed, as simulated numbers can't be bound. If there are several, none runs.