Via Webhooks

The simplest way to run a conversation with Phonic is via webhooks. If you followed the quick start guide, you’ve already had your first webhook conversation!

In this guide we’ll showcase two more important features of webhook conversations. The example code for this guide is available here.

Agent configuration endpoint

Typically, when you create an agent with Phonic you specify default values for its behavior, such as its welcome message and system prompt. With the agent configuration endpoint, you have the option at the start of every conversation to update your agent with conversation-specific information.

This is primarily useful for inbound calls; for example, your endpoint can look up the inbound caller in your CRM and populate your welcome message with the caller information.

Implementing your configuration endpoint is easy:

1import { Hono } from "hono";
2
3const app = new Hono();
4
5app.post("/webhooks/agent-config", async (c) => {
6 const body = (await c.req.json()) as Phonic.PhonicConfigurationEndpointRequestPayload;
7 const fromPhoneNumber = body.from_phone_number;
8 const fromCustomerName = lookUpCustomerName(fromPhoneNumber); // look up customer in your CRM
9 const response: Phonic.PhonicConfigurationEndpointResponsePayload = {
10 welcome_message: `Hey ${fromCustomerName}, how can I help you today?`,
11 };
12 return c.json(response);
13});

Post-call analysis endpoint

Upon the completion of each conversation, you can report conversation information, such as the full transcript, system prompt, and start/end timestamps. Implementing this is also easy:

1import { Hono } from "hono";
2
3const app = new Hono();
4
5app.post("/webhooks/post-call", async (c) => {
6 const body = await c.req.json();
7 save_conversation(body); // save conversation information to your database
8 return c.json({ message: "OK" });
9});
See here for a complete code example.