---
title: "Complete integration example"
description: "Follow a complete custom integration flow: create a session, send a user message, receive the AI agent reply, and tag the conversation."
---

# Complete integration example

> Follow a complete custom integration flow: create a session, send a user message, receive the AI agent reply, and tag the conversation.

A typical integration flow from session creation to receiving a bot response.

**Step 1: Create a session**

```
curl -X POST "https://channels.moveo.ai/v1/custom/YOUR_INTEGRATION_ID/sessions" \
  -H "Authorization: apikey YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "external_session_id": "chat-session-001",
    "channel_user_id": "user-12345",
    "channel_type": "chat",
    "context": {
      "user": {
        "display_name": "Alice Smith",
        "email": "alice@example.com",
        "language": "en"
      },
      "source_page": "pricing"
    }
  }'
```

Response:

```json
{
  "request_id": "req-001",
  "session_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "context": { ... }
}
```

**Step 2: Send a user message**

```
curl -X POST "https://channels.moveo.ai/v1/custom/YOUR_INTEGRATION_ID/sessions/a1b2c3d4-e5f6-7890-abcd-ef1234567890/messages" \
  -H "Authorization: apikey YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "input": {
      "text": "What pricing plans do you offer?"
    }
  }'
```

Response:

```json
{
  "request_id": "req-002"
}
```

**Step 3: Receive bot response on your webhook**

Moveo delivers the AI agent's response to your webhook URL:

```json
{
  "event_type": "message:brain_send",
  "request_id": "req-003",
  "session_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "external_session_id": "chat-session-001",
  "channel_type": "chat",
  "account_id": "acc-123",
  "account_slug": "acme-co",
  "timestamp": 1789084800000,
  "output": {
    "responses": [
      {
        "type": "text",
        "text": "We offer three pricing plans: Starter, Professional, and Enterprise.",
        "options": [
          { "label": "See Starter", "text": "Tell me about the Starter plan" },
          {
            "label": "See Professional",
            "text": "Tell me about the Professional plan"
          },
          {
            "label": "See Enterprise",
            "text": "Tell me about the Enterprise plan"
          }
        ]
      }
    ]
  }
}
```

**Step 4: Tag the conversation**

Tags added during the conversation show up in reporting and can drive routing rules.

```
curl -X PUT "https://channels.moveo.ai/v1/custom/YOUR_INTEGRATION_ID/sessions/a1b2c3d4-e5f6-7890-abcd-ef1234567890/context/tags" \
  -H "Authorization: apikey YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "tags": ["pricing-question"]
  }'
```

Response:

```json
{
  "tags": ["pricing-question"]
}
```

---

## Best practices

- **Verify webhook signatures**: always validate the `X-Moveo-Signature` header before processing webhook events. See [webhook security](https://docs.moveo.ai/api/custom-integration/custom-integration-webhook-security.md).
- **Respond quickly to webhooks**: process webhook events asynchronously. Return `200 OK` within 8 seconds and handle the event in a background job. A delivery that times out is not retried.
- **Never authorize on webhook headers**: the signature covers the body only. Read `account_id` and `session_id` from the verified body, not from the `X-Moveo-*` headers.
- **Store the session ID**: after creating a session, store the `session_id` in your system for all subsequent API calls.
- **Use context effectively**: pass relevant user and session data in the [`context` object](https://docs.moveo.ai/api/custom-integration/custom-integration-sessions.md#context-object) to give the AI agent more information for generating responses.
- **Change tags with the tag endpoints**: a `PATCH` to the context replaces the whole `tags` array, while [add tags](https://docs.moveo.ai/api/custom-integration/custom-integration-sessions.md#add-tags) and [remove tags](https://docs.moveo.ai/api/custom-integration/custom-integration-sessions.md#remove-tags) merge into it.
- **Handle session expiration**: listen for `session:expired` events to clean up local session state.
- **Stop on `410`**: an `integration-not-found` response means the integration was deleted. Retrying will never succeed.

---

## Next steps

- [AI agents](/docs/ai-agents/overview): configure the agent that powers your integration.
- [Environments](/docs/environments/environments-overview): understand how integrations work with environments.
- [Live chat](/docs/chat/chat-overview): set up human agent handover for your custom integration.
- [Context variables](/docs/ai-agents/context): learn how to use context variables in your AI agent.
