> For a complete index of all SignalWire documentation pages, fetch https://signalwire.com/docs/llms.txt

# Webhooks

> An introduction to using webhooks to receive information and events about calls and messages.

[Webhooks](https://en.wikipedia.org/wiki/Webhook) are HTTP requests sent to your server from SignalWire when an event occurs.
They help receive information about events like inbound calls to your phone numbers, or messages.

In addition to getting information about events, some webhooks also allow you to tell SignalWire how an event should be handled.

During development, you can use localhost tunneling applications like [ngrok](https://ngrok.com) to test your webhook handlers locally.
See [the ngrok quickstart guide](https://ngrok.com/docs/getting-started) to get started.

## Configure webhooks for phone numbers

To handle an inbound call or message, you point your phone number at a [Resource](/docs/platform/resources) that holds your webhook URL.
When an event arrives, SignalWire requests that URL and your server responds with [SWML](/docs/swml), the SignalWire Markup Language that tells SignalWire how to handle the call.

```mermaid
flowchart LR
    A["Incoming message"] --> B[SignalWire]
    B --> C["Webhook HTTP request to your server"]
    C --> D[[Your webhook handler]]
    D --> F["Generate SWML to reply to the message"]
    F -- "200 OK, SWML" --> B
```

[Resources](/docs/platform/resources) are the building blocks of SignalWire applications. They include AI Agents, SWML Scripts, cXML Scripts, SIP Endpoints, and more.

### Create a Resource for your webhook URL

In the SignalWire Dashboard, open the **My Resources** tab and click **+ Add**, then choose **SWML Script**.

![Selecting a Resource type in the SignalWire Dashboard](https://files.buildwithfern.com/signalwire.docs.buildwithfern.com/655141c0c1d0f5f0f6c06f23ffdd65b8495fc29d7728aede06395c183e6a9b42/assets/images/dashboard/resources/add-new-resource.webp)

Give the script a name, set **Handle Calls Using** to **External URL**, and enter your webhook URL in the **Primary Script URL** field. Click **Create** to save the Resource.

![Configuring a SWML Script Resource with an external URL in the SignalWire Dashboard](https://files.buildwithfern.com/signalwire.docs.buildwithfern.com/43a003e28afd6244858c0addf33ffa6c2dcac6da942e418bdd70a4ee1bd8eea0/assets/images/dashboard/resources/external-swml-script.webp)

### Assign the Resource to your phone number

Open the **Phone Numbers** tab and select the number you want to configure.

![The Phone Numbers tab of a SignalWire Space showing a list of phone numbers](https://files.buildwithfern.com/signalwire.docs.buildwithfern.com/860651f34bc9df5c3b3acabf6e1479d7b37907e3cf6ba2174700a04210d7af41/assets/images/dashboard/phone-numbers/purchased-phone-numbers.webp)

Click **Edit Settings**. Under **Inbound Call Settings** (or **Inbound Message Settings** for messaging), choose **Assign Resource**, select the Resource you created, and click **Save**.

![A phone number's settings page showing the Assign Resource option for inbound calls](https://files.buildwithfern.com/signalwire.docs.buildwithfern.com/c293c9af028b3a827d818c19cc568273e100ddcebb2e89b09fb6b0c998a98366/assets/images/dashboard/phone-numbers/assign-resource-full.webp)

A full walkthrough of connecting a phone number to your application.

How to purchase and manage phone numbers in your SignalWire Space.

Learn how to handle incoming calls and messages from code.

## Status callbacks to keep track of events

Status callbacks are asynchronous HTTP requests SignalWire sends to your server as a call,
message, or recording moves through its lifecycle, so your application can react to each state change as it happens.

```mermaid
flowchart LR
    A["Inbound Call"] --> B[SignalWire]
    B --> C["Webhook HTTP request to your server"]
    C --> D[[Your webhook handler]]
    D --> E[(Database)]
    D --> F[Other internal services]
```

You subscribe to a status callback **programmatically**: when you create the call or message, provide a callback URL on the relevant SWML method,
and SignalWire posts to it each time the state changes.
What you set and the states you receive depend on what you're tracking:

| To track        | Provide a callback URL on                                                                                                                    | States you'll receive                                                       |
| :-------------- | :------------------------------------------------------------------------------------------------------------------------------------------- | :-------------------------------------------------------------------------- |
| **Voice calls** | `call_state_url` on [`connect`](/docs/swml/reference/calling/connect)                                                                        | `created`, `ringing`, `answered`, `ended`                                   |
| **Messages**    | `status_callback` on [`send_sms`](/docs/swml/reference/calling/send-sms), or `status_url` on [`reply`](/docs/swml/reference/messaging/reply) | `queued`, `initiated`, `sent`, `delivered`, `undelivered`, `failed`, `read` |
| **Recordings**  | `status_url` on [`record_call`](/docs/swml/reference/calling/record-call)                                                                    | `recording`, `paused`, `finished`, `no_input`, `error`                      |

For voice calls, `call_state_events` defaults to `['ended']` — set it explicitly to also receive `created`, `ringing`, and `answered`.

SignalWire only marks a message **Delivered** once it receives a Delivery Receipt (DLR) confirming the message reached the end carrier's network.
A status of **Sent** means the message left SignalWire successfully.
MMS messages do not support DLRs, so they only ever show **Sent**.

The full field reference and status values for outbound message status callbacks.

Receive 10DLC campaign registration status updates via webhooks.

## Verify webhook signature

To verify webhooks that originated from SignalWire, SignalWire signs its requests with a digital HMAC security key.
You can verify that the security key matches the key documented in your Dashboard's [API Credentials](https://my.signalwire.com?page=credentials) with the `validateRequest` method.

![The API Credentials page in a SignalWire Space showing the signing key](https://files.buildwithfern.com/signalwire.docs.buildwithfern.com/7a4604377a0fec7f6af79e69e0208c0238762ed3f3c177dcda899c33602ddf81/assets/images/dashboard/credentials/api-credentials-with-signing-key.webp)

For production applications, it is extremely important to verify the webhook signature to ensure the requests are coming from SignalWire and not a malicious third party.

```js
import { validateRequest } from "@signalwire/js";

// prepare raw body for validation
app.use(express.json({
  verify: (req: any, _res, buf) => {
    req.rawBody = buf.toString();
  }
}));

app.post("/mywebhook", (req: any, res) => {
  const valid = validateRequest(
    "<SIGNING_KEY_FROM_Dashboard>",
    req.headers["x-signalwire-signature"] as string,
    "https://example.ngrok.io/mywebhook", //this should be the public-facing URL of your webhook handler
    req.rawBody
  );

  if (!valid) return res.status(401).send("Invalid signature");

  res.sendStatus(200);
});
```