> For the complete documentation index, see [llms.txt](https://docs.immedio.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.immedio.io/guides/ai-sdr-trigger.md).

# AI接客トリガー（ホストサイト連携）

## AI接客トリガーとは

AI接客トリガーとは、ホストサイト側のJavaScriptからAI接客チャットの表示やメッセージ送信を行える機能です。ブラウザのCustomEventを使って、任意のボタンやリンクのクリックなど、ホストサイト側の操作をきっかけにAI接客の会話を開始できます。

たとえば「料金について聞く」ボタンをWebサイト上に配置し、クリック時にAI接客へメッセージを自動送信することで、リードが手入力せずにスムーズに会話を始められます。

## AI接客トリガーでできること

| 機能         | 説明                                                                     |
| ---------- | ---------------------------------------------------------------------- |
| メッセージの自動送信 | ホストサイトからAI接客チャットへ任意のメッセージを送信できます                                       |
| チャットの表示・展開 | イベント発火時にチャットウィジェットが最小化・非表示だった場合、自動的に開いた状態になります。メッセージなしで発火すると、表示のみを行えます |

## イベント仕様

### イベント名

`immedio-trigger:send-ai-sdr-message`

### イベントの種類

ブラウザ標準の `CustomEvent` を使用します。`window.dispatchEvent()` でイベントを発火します。

### detail（イベントデータ）

| 項目      | 型          | 説明                                                         |
| ------- | ---------- | ---------------------------------------------------------- |
| message | string（任意） | AI接客チャットに送信するメッセージ。省略した場合、チャットウィジェットの表示のみ行われ、メッセージは送信されません |

### 動作の流れ

1. ホストサイト側でCustomEventを発火します
2. AI接客チャットが最小化・非表示の場合、自動的に開いた状態になります
3. `detail.message` にメッセージを指定した場合、その内容がリードの発言としてAIに送信されます
4. AIが応答を返します

## 使い方（サンプルコード）

以下のコードを、immedioタグが読み込まれているページに配置すると、任意のタイミングでAI接客にメッセージを送信できます。

### 基本的な使い方

```javascript
window.dispatchEvent(new CustomEvent('immedio-trigger:send-ai-sdr-message', {
  detail: { message: '料金を教えて' },
}));
```

### チャットウィジェットの表示のみ行う（メッセージなし）

`detail.message` を省略すると、メッセージは送信されず、チャットウィジェットの表示のみ行われます。最小化・非表示状態のウィジェットを開いた状態にしたい場合に使用します。

```javascript
window.dispatchEvent(new CustomEvent('immedio-trigger:send-ai-sdr-message'));
```

AI接客の基本設定で[「デフォルトの表示状態」を「非表示」](/company-settings/ai-sdr/basic-settings.md#default-state-hidden)にしている場合、ウィジェットはこのイベントを発火するまで表示されません。「サイト側の任意のタイミングでのみAI接客を出したい」場合は、「非表示」設定とこのイベントを組み合わせてください。

### ボタンクリック時に発火する例

```html
<button onclick="window.dispatchEvent(new CustomEvent('immedio-trigger:send-ai-sdr-message', { detail: { message: '料金プランについて教えてください' } }))">
  料金について聞く
</button>
```

### 複数のボタンを配置する例

```html
<button onclick="window.dispatchEvent(new CustomEvent('immedio-trigger:send-ai-sdr-message', { detail: { message: 'デモを予約したい' } }))">
  デモを予約する
</button>

<button onclick="window.dispatchEvent(new CustomEvent('immedio-trigger:send-ai-sdr-message', { detail: { message: '導入事例を教えてください' } }))">
  導入事例を見る
</button>
```

### 検索バーの入力内容をAI接客に送信する例

検索バーに入力された任意の文字列を、AI接客へそのまま送信する例です。リードが検索バーに質問を入力して送信ボタンを押すと、その内容がAI接客チャットに転送されます。

```html
<form onsubmit="event.preventDefault(); var input = this.querySelector('input'); var message = input.value.trim(); if (message) { window.dispatchEvent(new CustomEvent('immedio-trigger:send-ai-sdr-message', { detail: { message: message } })); input.value = ''; }">
  <input type="text" placeholder="AIに質問する..." />
  <button type="submit">送信</button>
</form>
```

## 注意事項

* イベントを発火するには、immedioのタグが読み込まれており、AI接客が有効になっている必要があります
* `detail.message` が空文字または空白のみの場合、メッセージは送信されず、ウィジェットの表示のみ行われます
* AI接客のチャット履歴の読み込みが完了する前にイベントが発火された場合、メッセージは送信されません

## 関連

* [AI接客 基本設定](/company-settings/ai-sdr/basic-settings.md)
* [AI接客 フロー設定](/company-settings/ai-sdr/flow.md)
* [immedioイベント（ブラウザイベント連携）](/guides/immedio-events.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.immedio.io/guides/ai-sdr-trigger.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
