> This is a page from the ElevenLabs documentation. For a complete page index, fetch https://elevenlabs.io/docs/llms.txt. For the full documentation in a single file, fetch https://elevenlabs.io/docs/llms-full.txt.

# Supabase

Receptionistは、SupabaseのREST APIを通じて、通話の詳細をSupabaseテーブルに保存し、電話番号で発信者を検索できます。以下の設定では、行レベルセキュリティを適用したプロジェクトの公開キーを使用するため、Receptionistは許可された操作のみ実行できます。

> **Warning**
>
> Webhookツールには`service_role`やシークレットキーを決して設定しないでください。これらのキーは行レベルセキュリティを回避し、
> データベースへのフルアクセスを許可します。

## はじめる前に

Supabaseダッシュボードで **Project Settings** → **API Keys** を開き、**publishable** キーまたは従来の **anon** キーをコピーします。プロジェクトURLは`https://PROJECT_REF.supabase.co`です。

## データベースを準備する

**SQL Editor** で以下を実行します。Receptionistが挿入のみ行えるテーブルと、完全に一致する電話番号から1人の顧客を返す関数が作成されます。この関数は、`name`、`plan`、`notes`、`phone`列を持つ既存の`customers`テーブルを前提としているため、使用中のスキーマに合わせて名前を調整してください。

発信者がこの関数を使って顧客一覧を取得することはできません。電話番号が完全に一致しない限り、何も返されません。

```sql
create table callback_requests (
  id bigint generated always as identity primary key,
  created_at timestamptz not null default now(),
  caller_name text not null,
  phone text not null,
  reason text not null
);

alter table callback_requests enable row level security;

create policy "Receptionist can add callback requests"
  on callback_requests for insert to anon
  with check (true);

create function find_customer_by_phone(phone text)
returns table (name text, plan text, notes text)
language sql stable security definer set search_path = public
as $$
  select c.name, c.plan, c.notes from customers c where c.phone = find_customer_by_phone.phone limit 1;
$$;

revoke execute on function find_customer_by_phone from public;
grant execute on function find_customer_by_phone to anon;
```

## ツールを作成する

両方のツールについて、**Integrations** に移動して **Add integration** を選択し、**Webhook Tool** を選んで、次のリクエストヘッダーを追加します。

| ヘッダー            | 値                                                |
| --------------- | ------------------------------------------------ |
| `apikey`        | publishableキーまたはanonキー                           |
| `Authorization` | `Bearer `の後にanonキーを続けたもの。publishableキーの場合は省略します。 |

### 折り返しリクエストを保存する

| フィールド            | 値                                                           |
| ---------------- | ----------------------------------------------------------- |
| **名前**           | `save_callback_request`                                     |
| **説明**           | 「発信者にフォローアップを約束したときは、必ず折り返しリクエストを保存します。」                    |
| **メソッド**         | POST                                                        |
| **URL**          | `https://PROJECT_REF.supabase.co/rest/v1/callback_requests` |
| **本文パラメーター**     | `caller_name`、`phone`、`reason`（すべて文字列、必須）                   |
| **エージェントへの割り当て** | **Receptionist**                                            |

### 顧客を検索する

| フィールド            | 値                                                                    |
| ---------------- | -------------------------------------------------------------------- |
| **名前**           | `find_customer`                                                      |
| **説明**           | 「電話番号で発信者のアカウントを検索します。発信者からプランやアカウントについて質問されたときに使用してください。」           |
| **メソッド**         | POST                                                                 |
| **URL**          | `https://PROJECT_REF.supabase.co/rest/v1/rpc/find_customer_by_phone` |
| **本文パラメーター**     | `phone`（文字列、必須）：「E.164形式の発信者の電話番号（例：+14155550123）。」                  |
| **エージェントへの割り当て** | **Receptionist**                                                     |

各ツールで **Enable** を選択し、折り返しリクエストで[Receptionistをテスト](/docs/ja/reception-ai/receptionist/testing)します。行が **Table Editor** に表示されます。

## トラブルシューティング

| 問題                                           | 確認事項                                             |
| -------------------------------------------- | ------------------------------------------------ |
| `new row violates row-level security policy` | 挿入ポリシーの対象を`anon`ロールにする必要があります。                   |
| `Could not find the function`                | 本文パラメーター名は、関数の引数（ここでは`phone`）と完全に一致する必要があります。    |
| 401 `Invalid API key`                        | publishableキーを使用する場合は、`Authorization`ヘッダーを削除します。 |
| 顧客が見つからない                                    | Receptionistが送信する形式と同じE.164形式で電話番号を保存してください。     |