> ## Documentation Index
> Fetch the complete documentation index at: https://docs.molin.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Phone personalization

> Shops with a Molin phone number: look callers up in your own system by their number, so your AI greets them by name and knows their orders.

Shops with a Molin phone number: your AI can know who is calling before it says a word. It looks the caller up by the phone number they call from, greets them by name and already knows their recent orders.

## What works automatically

Caller recognition is on for every shop with a phone number. What your AI finds depends on your platform:

| Platform | Who is recognized |
| - | - |
| Shopify | any caller saved as a customer with this phone number, even if they never ordered |
| Shoper | callers who ordered before with this phone number |
| UNAS, Shoprenter | callers who ordered before with this phone number, orders placed in the last hour may not be found yet |
| other shops | nobody, unless you connect your own endpoint below |

You see the same summary for your platform on the [Phone page](https://molin.ai/app/channels/phone) under **Caller recognition**.

## Connect your own customer data

Connect your own endpoint when your platform cannot recognize every caller, or when you know more about your customers than your shop platform does, such as loyalty status, a CRM record or orders from another system.

1. Build an HTTPS endpoint that follows the contract below.
2. On the [Phone page](https://molin.ai/app/channels/phone), open **Caller recognition** and click **Set up**.
3. Enter your endpoint URL, choose `POST` or `GET`, and pick the login your endpoint needs.
4. Enter a phone number and click **Test** to see your endpoint's answer and exactly what your AI receives.
5. Click **Save**.

From then on, every incoming call sends one request to your endpoint.

### Request

Molin calls your endpoint as soon as a call arrives, with the method you choose: `POST` (the default) or `GET`.

A `POST` request sends the caller in a JSON body:

```http theme={null}
POST https://your-shop.com/molin/caller
Content-Type: application/json
Authorization: Bearer your-key
x-molin-widget-id: your-widget-id
x-molin-caller-number: +36301234567

{ "callerNumber": "+36301234567", "widgetId": "your-widget-id" }
```

A `GET` request sends the same values in the link:

```http theme={null}
GET https://your-shop.com/molin/caller?callerNumber=%2B36301234567&widgetId=your-widget-id
Authorization: Bearer your-key
x-molin-widget-id: your-widget-id
x-molin-caller-number: +36301234567
```

* `callerNumber` is the number the call comes from, in international format. It comes from the phone line, never from what the caller says, so a caller cannot ask about someone else.

### Login

Choose how Molin proves the request comes from it, with the same options as [custom actions](https://docs.molin.ai/apis/custom-actions.md):

| Login | What Molin sends |
| - | - |
| No login needed | nothing extra |
| Username and password | `Authorization: Basic …` |
| Key or token, sent as the `Authorization` header | `Authorization: Bearer your-key` |
| Key or token, sent as another header | that header, such as `X-Api-Key: your-key` |
| Key or token, sent in the link | a query parameter, such as `?api_key=your-key` |

The password, key or token stays on our server and is never shown again, not even to the AI. Changing the endpoint address or the login type asks you to enter it again.

### Response

Answer with JSON in the same shape as the [Personalization API](https://docs.molin.ai/apis/experimental/personalization-api.md) your website uses:

```json theme={null}
{
  "userData": {
    "name": "Kiss Anna",
    "email": "anna@example.com",
    "loyalty_tier": "gold"
  },
  "customInstructions": "Order 1042 shipped on 28 November with GLS, tracking number 1234. Loyal customer since 2021, offer free shipping on the next order."
}
```

* `userData` is a flat object of text, number, true/false or `null` values. Nested objects and lists are not accepted, put those in `customInstructions` as text.
* `userData.name` is the name your AI greets the caller by.
* `customInstructions` is text your AI follows for this call, up to 5,000 characters.
* Both fields are optional. Answer `{}` or a `404` status when you don't know the caller.
* Your team sees both on the call's conversation in the Inbox.

### Limits and errors

* Answer within 10 seconds. Your AI picks up the call without waiting, and uses the caller's name in its greeting only if your answer has already arrived. A later answer is still used for the rest of the call.
* The response must be under 8,000 characters.
* If your endpoint is down, slow, or answers with anything other than the format above, the call goes on as if the caller were unknown.
* A call that reconnects after a brief interruption on our side sends the request again, so answer the same number the same way each time.

> [!NOTE]
>
> If your calls reach Molin through your own switchboard or a forwarding service, the caller number may be your switchboard's number for every call. Your endpoint then receives that number, so answer
> `{}` for it instead of returning a customer.

### Example endpoint

A minimal Node.js endpoint with no dependencies:

```javascript theme={null}
import { createServer } from 'node:http';

const SECRET = process.env.MOLIN_SECRET;

// replace with a lookup in your own database or CRM
async function findCustomerByPhone(phone) {
  if (phone === '+36301234567') {
    return { name: 'Kiss Anna', loyalty_tier: 'gold', lastOrder: 'Order 1042 shipped on 28 November with GLS.' };
  }
  return null;
}

createServer(async (req, res) => {
  if (req.method !== 'POST' || req.url !== '/molin/caller') {
    res.writeHead(404).end();
    return;
  }
  if (SECRET && req.headers.authorization !== `Bearer ${SECRET}`) {
    res.writeHead(401).end();
    return;
  }

  let body = '';
  for await (const chunk of req) {
    body += chunk;
  }
  const { callerNumber } = JSON.parse(body);

  const customer = await findCustomerByPhone(callerNumber);
  if (!customer) {
    res.writeHead(404).end();
    return;
  }

  res.writeHead(200, { 'Content-Type': 'application/json' });
  res.end(
    JSON.stringify({
      userData: { name: customer.name, loyalty_tier: customer.loyalty_tier },
      customInstructions: customer.lastOrder,
    }),
  );
}).listen(3000);
```

## Look things up during the call

To let your AI look something up later in the call, for example an order the caller asks about, use a [custom action](https://docs.molin.ai/apis/custom-actions.md) with **Send the caller's phone number** turned on. See [Identify the caller](https://docs.molin.ai/apis/custom-actions.md#identify-the-caller).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.