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

# Step 1 — Connect real-time events

> Give Lyro live awareness of what each user is doing — Lyro pulls it on demand via an Action that calls the Autoplay MCP server.

## ⚡ Add this skill

<CardGroup cols={2}>
  <Card title="One command" icon="terminal">
    Add the Autoplay Tidio Lyro skill for an existing Tidio Lyro AI support agent setup.

    <CodeGroup>
      ```bash CLI theme={null}
      uvx --from autoplay-sdk autoplay-install-skills --chatbot tidio
      ```
    </CodeGroup>

    <a className="skill-card-link" href="/recipes/tidio/step-1-connect-real-time-events">View the docs →</a>
  </Card>

  <Card title="Agent onboarding" icon="robot">
    Fetch this skill when a customer already uses Tidio Lyro and wants its AI support agent to consume Autoplay live user activity.

    <CodeGroup>
      ```bash cURL theme={null}
      curl -s https://developers.autoplay.ai/chatbot-tidio/SKILL.md
      ```
    </CodeGroup>

    <a className="skill-card-link" href="https://developers.autoplay.ai/chatbot-tidio/SKILL.md" target="_blank">View the skill →</a>
  </Card>
</CardGroup>

**Lyro** (Tidio's AI agent) pulls a user's recent in-app activity on demand via a **Lyro Action** — a named API call that Lyro triggers when it needs context to answer. One Action, one API call to the Autoplay MCP server, and a user id wired in from the visitor session.

## 🎬 End-to-end walkthrough

<div
  style={{
position: "relative",
paddingBottom: "56.25%",
height: 0,
width: "100%",
}}
>
  <iframe
    src="https://www.youtube.com/embed/9cf5BhQydCI"
    title="Tidio Lyro AI Agent responding with real-time user context"
    frameBorder={0}
    loading="lazy"
    allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
    allowFullScreen
    style={{
  position: "absolute",
  top: 0,
  left: 0,
  width: "100%",
  height: "100%",
}}
  />
</div>

***

## 🤖 Create the Action

In your Tidio dashboard, go to **Lyro AI Agent** → **Actions** → **+ Create Action** → **Create from scratch**.

### Name

Give the Action a clear, descriptive name — Lyro uses the name as context for when to trigger it:

```
Get Live User Activity
```

### Instructions

The Instructions field tells Lyro **when** to call this Action. Fill it in with:

```text theme={null}
Call this action before responding to any message where
knowing what the user has recently done in the app would
help give a better answer. This includes:

- User seems stuck or asks where something is
- User asks about something they were just doing
- User mentions an error or unexpected behavior
- You need to understand their recent navigation to give
  specific directions instead of a generic walkthrough

No information is required from the user — call this action
directly. It returns a chronological list of recent in-app
activity: pages visited, buttons clicked, forms submitted.

Do NOT call this action when:
- The user is asking about billing or account details
- The question can be answered without knowing recent activity
```

***

## ⚙️ Build the Action sequence

Click **Create sequence** in the Action sequence section.

In the sequence builder, click the empty step and select **API call** from the right panel.

### Configure the API call

Set up the API call to the Autoplay MCP server:

* **Method:** `POST`
* **URL:** `https://mcp.autoplay.ai/mcp`

Under **Headers**, add:

| Key             | Value                 |
| --------------- | --------------------- |
| `Authorization` | `Bearer YOUR_MCP_KEY` |
| `Content-Type`  | `application/json`    |

Under **Body**, paste:

```json theme={null}
{
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "name": "get_live_user_activity",
    "arguments": {
      "product_id": "YOUR_PRODUCT_ID",
      "user_id": "{{contact.user_id}}"
    }
  },
  "id": 1
}
```

<Tip>
  Replace `YOUR_PRODUCT_ID` with your actual product id from
  your Autoplay dashboard. `{{contact.user_id}}` is a Tidio
  template variable — see *Identity* below for how to set it.
</Tip>

### Save the response

After the API call step, add an **Update session variable** step. Save the activity data from the response so Lyro can reference it when composing its reply:

* **Variable name:** `activity`
* **Value:** the `result.content[0].text` field from the API response

Click **Save and close**.

***

## 🔐 Identity — wire the user id into the session

Lyro needs the current user's stable id to pass as `user_id` in the API call. Set it from your frontend via the Tidio JS SDK **after the user logs in**:

```javascript theme={null}
// After login — set your app's stable user id on the Tidio contact.
// This becomes available as {{contact.user_id}} in Lyro Actions.
window.tidioChatApi.on("ready", function () {
  window.tidioChatApi.setVisitorData({
    custom: {
      user_id: currentUser.id,
    },
  });
});
```

The value you set **must exactly equal** the id your activity source uses:

<Tabs>
  <Tab title="PostHog">
    ```javascript theme={null}
    // These two must be identical:
    posthog.identify(currentUser.id);      // activity source

    window.tidioChatApi.on("ready", function () {
      window.tidioChatApi.setVisitorData({
        custom: { user_id: currentUser.id },
      });
    });
    ```
  </Tab>

  <Tab title="Amplitude">
    ```javascript theme={null}
    // These two must be identical:
    amplitude.setUserId(currentUser.id);   // activity source

    window.tidioChatApi.on("ready", function () {
      window.tidioChatApi.setVisitorData({
        custom: { user_id: currentUser.id },
      });
    });
    ```
  </Tab>
</Tabs>

<Note>
  **How the pieces fit:** your frontend identifies the user
  in your activity source → Autoplay stores activity under
  that id → your frontend also sets `custom.user_id` on the
  Tidio contact → Lyro reads `{{contact.user_id}}` and passes
  it in the API call → the buckets match.
</Note>

## 💬 Update the Guidance instructions

Go to **Lyro AI Agent** → **Behavior** → **Guidance** → **Communication Style** → **Custom**. Add this to the instructions so Lyro knows how to use the activity data returned by the Action:

```text theme={null}
When you call the "Get Live User Activity" action, use the
returned activity to understand where the user is in the
product and what they've already tried. Reference it to give
specific, context-aware answers instead of generic walkthroughs.

Do not mention the activity data directly — just use it to
give better, more targeted answers.
```

## ✅ Test the full loop

1. **Log in** to your app as a test user — fires your activity source's identify call and sets `custom.user_id` on the Tidio contact.
2. **Click around** — visit a couple of pages, click a button, submit a form.
3. **Open the Tidio chat widget** as that same logged-in user.
4. **Ask Lyro:** *"What have I been doing in the app recently?"*
5. Lyro triggers **Get Live User Activity**, calls the Autoplay MCP server, and answers with **what you actually just did**.

Common issues:

* **401 / auth error** → the `Authorization` header is missing or the token is wrong — revisit the API call headers above.
* **Empty activity returned** → identity is working but that user has no recent activity yet. Browse around in your app first, then re-test.
* **Wrong user's activity** → `{{contact.user_id}}` doesn't match the id your activity source uses. Check both are identical.

<Note>
  **"No recent activity" = identity mismatch.** Confirm the
  **same** value in all three:

  1. the stable id your activity source identifies the user
     with (PostHog: `posthog.identify(id)`,
     Amplitude: `amplitude.setUserId(id)`),
  2. the `custom.user_id` you set via `tidioChatApi.setVisitorData`,
  3. the `{{contact.user_id}}` referenced in the Action's
     API call body.

  If they don't match, activity is stored under one key
  and fetched with another, and the lookup comes back empty.
</Note>

Once Lyro is answering with real activity, jump into our [Discord](https://discord.gg/jCbR2tQA5) — we'll confirm the Action is calling correctly and help you tune the trigger instructions.

***

**Next:** [Step 2 — Define proactive triggers](./step-2-define-proactive-triggers)
