> ## Documentation Index
> Fetch the complete documentation index at: https://docs-dev-update-anonymous-sessons-ea.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# カスタム電話プロバイダーを設定する

> デフォルトの電話プロバイダーではなく任意のゲートウェイを介して Auth0 の SMS および音声メッセージを送信する、custom-phone-provider Action を実装します。

[ユーザー識別子として電話番号を使用する](/docs/ja-jp/authenticate/database-connections/activate-and-configure-attributes-for-flexible-identifiers)場合は、SMS 用のカスタム電話プロバイダーを設定できます。カスタム電話プロバイダーでは、電話番号の確認やパスワードのリセット時に、[Actions](/docs/ja-jp/customize/actions/actions-overview) を使って、任意の電話プロバイダーに SMS メッセージを送信できます。

次のようなユースケースでは、カスタム電話プロバイダーの設定が役立ちます。

* アプリケーションのコンテキストに応じて、異なる電話プロバイダーを使い分ける。たとえば、電話プロバイダーのメッセージ料金が地域によって大きく異なる場合があります。
* 組織コンテキストに応じて、異なる電話プロバイダーを使い分ける。B2B 顧客によっては、特定のプロバイダーの利用が求められる場合があります。

<Tooltip tip="Auth0 Dashboard: サービスを設定するための Auth0 の主要製品。" cta="用語集を表示" href="/docs/ja-jp/glossary?term=Auth0+Dashboard">Auth0 Dashboard</Tooltip> または <Tooltip tip="Auth0 Dashboard: サービスを設定するための Auth0 の主要製品。" cta="用語集を表示" href="/docs/ja-jp/glossary?term=Management+API">Management API</Tooltip> を使用して、カスタム電話プロバイダーを設定できます。

<h2 id="configure-a-custom-phone-provider-with-the-auth0-dashboard-or-management-api">
  Auth0 Dashboard または Management API を使用してカスタム電話プロバイダーを設定する
</h2>

カスタム電話プロバイダーを設定するには、Auth0 Actions Editor では使用できない `custom-phone-provider` Action トリガーを使用する必要があります。詳細については、[custom-phone-provider Action の例](#example-custom-phone-provider-action)を参照してください。

<Tabs>
  <Tab title="Auth0 Dashboard">
    <h4 id="add-a-custom-phone-provider-with-the-auth0-dashboard">
      Auth0 Dashboard でカスタム電話プロバイダーを追加する
    </h4>

    Auth0 Dashboard で新しいカスタム電話プロバイダーを設定するには、次の手順に従います。

    1. [Branding > Phone Provider](https://manage.auth0.com/dashboard/#/phone/templates/phone/provider) に移動します。Phone Message Provider ページが表示されます。デフォルトでは、Twilio の 電話プロバイダー が選択されています。
    2. Phone Provider セクションで、**Custom** 電話プロバイダー オプションを選択します。
    3. **Delivery Method:** を選択します。

       1. Text: 確認コードは SMS でユーザーに送信されます。
       2. Voice: 確認コードは Voice Message でユーザーに送信されます。
    4. **Provider Configuration** で、カスタム電話プロバイダーを設定するための Actions コードを記述します。

       1. メッセージをプロバイダーの API に送信する方法を確認するため、プロバイダーのドキュメントを参照してください。
       2. API での認証に必要な secrets を追加します。
       3. (任意) **Edit in Expanded Editor** ボタンをクリックすると、完全な Actions editor インターフェイスで Action を編集できます。Actions editor で Action を編集したら、その画面で Action を **Save** して **Deploy** します。その後、Actions editor ページ上部の **Back to Phone Provider** リンクをクリックして Phone Message Provider ページに戻ります。戻ったら、Phone Provider セクションで **Custom** 電話プロバイダー オプションを再度選択する必要があります。
    5. ページ下部の **Save** ボタンをクリックします。

    **Save** をクリックすると、Action は自動的に保存され、デプロイされます。本番環境で使用する前にカスタム電話プロバイダーの設定をテストするには、**Send Test Message** をクリックします。

    <Callout icon="file-lines" color="#0EA5E9" iconType="regular">
      カスタム電話プロバイダーの設定を保存するまでは、**Send Test Message** をクリックしてテストすることはできません。
    </Callout>

    <h4 id="edit-a-custom-phone-provider-with-the-auth0-dashboard">
      Auth0 Dashboard でカスタム電話プロバイダーを編集する
    </h4>

    Auth0 Dashboard で既存のカスタム電話プロバイダーを編集するには、次の手順に従います。

    1. [Branding > Phone Provider](https://manage.auth0.com/dashboard/#/phone/templates/phone/provider) に移動します。Phone Message Provider ページが表示されます。
    2. 必要に応じて、Phone Message Provider ページで Action コードを変更します。

       1. (任意) **Edit in Expanded Editor** ボタンをクリックすると、完全な Actions editor インターフェイスで Action を編集できます。Actions editor で Action を編集したら、その画面で Action を **Save** して **Deploy** します。次に、Actions editor ページ上部の **Back to Phone Provider** リンクをクリックします。
    3. ページ下部の **Save** ボタンをクリックします。

    **Save** をクリックすると、Action は自動的に保存され、デプロイされます。本番環境で使用する前にカスタム電話プロバイダーの設定をテストするには、**Send Test Message** をクリックします。
  </Tab>

  <Tab title="Management API">
    <h4 id="add-a-custom-phone-provider-with-the-management-api">
      Management API でカスタム電話プロバイダーを追加する
    </h4>

    Management API を使用してカスタム電話プロバイダーを設定することもできます。これには複数の手順があります。

    1. [Action](https://auth0.com/docs/api/management/v2/actions/post-action) を作成し、`supported_triggers.id` を `custom-phone-provider` に設定します。

       1. メッセージをプロバイダーの API に送信する方法を確認するため、プロバイダーのドキュメントを参照してください。
       2. API での認証に必要な secrets を追加します。
    2. Action を [Deploy](https://auth0.com/docs/api/management/v2/actions/post-deploy-action) します。
    3. [電話プロバイダー](https://auth0.com/docs/api/management/v2/branding/create-phone-provider) を `custom` に設定します。

    <Callout icon="file-lines" color="#0EA5E9" iconType="regular">
      `custom-phone-provider` トリガーで作成した Action は、Actions library には表示されません。
    </Callout>

    <Callout icon="file-lines" color="#0EA5E9" iconType="regular">
      Action がデプロイされていない状態で `custom` provider を設定しようとすると、Auth0 は `"errorCode":"custom_email_provider_deployed_action_not_found"` を含むエラーを返します。
    </Callout>

    <h4 id="edit-a-custom-phone-provider-with-the-management-api">
      Management API でカスタム電話プロバイダーを編集する
    </h4>

    Management API を使用してカスタム電話プロバイダーを編集することもできます。

    1. (任意) 特定の Action ID がわからない場合は、Management API を使用して [actions の一覧を取得](https://auth0.com/docs/api/management/v2/actions/get-actions) できます。レスポンスには Actions object が含まれます。カスタム電話プロバイダーに使用される Action は `supported_triggers.id` で識別でき、この値は `custom-phone-provider` に設定されている必要があります。
    2. 必要に応じて [Action を更新](https://auth0.com/docs/api/management/v2/actions/patch-action) します。
    3. Action を [Deploy](https://auth0.com/docs/api/management/v2/actions/post-deploy-action) します。
  </Tab>
</Tabs>

設定可能なカスタム電話プロバイダーの例として、[Twilio Verify](https://www.twilio.com/docs/verify) があります。詳しくは、[Twilio Verify を使用してカスタム電話プロバイダーを設定する](/docs/ja-jp/customize/phone-messages/configure-phone-messaging-providers/configure-a-custom-phone-provider/configure-a-custom-phone-provider-with-twilio-verify) をご覧ください。

<h2 id="example-custom-phone-provider-action">
  custom-phone-provider Action の例
</h2>

`custom-phone-provider` トリガーは `send-phone-message` トリガーとは異なります。カスタム電話プロバイダーの設定に `send-phone-message` トリガーは使用しないでください。詳しくは、以下をご覧ください。

* [Action トリガー: custom-phone-provider API オブジェクト](/docs/ja-jp/customize/actions/reference/custom-phone-provider/custom-phone-provider-api-object)
* [Action トリガー: custom-phone-provider イベントオブジェクト](/docs/ja-jp/customize/actions/reference/custom-phone-provider/custom-phone-provider-event-object)

以下のコードサンプルは、`send-phone-message` Action と同じ機能を持つ `custom-phone-provider` Action です。

```javascript lines expandable theme={null}
/**
* 電話通知の送信中に実行されるハンドラー*
* @param {Event} event - ユーザーおよびログイン時のコンテキストに関する詳細情報。
* @param {CustomPhoneProviderAPI} api - 電話通知の送信動作を変更するためのメソッドとユーティリティ。
*/
exports.onExecuteCustomPhoneProvider = async (event, api) => {

  if (event.notification.message_type.startsWith('otp')) {
    const body = {
      from: event.notification.from,
      action: event.notification.message_type === 'otp_verify' ? 'second-factor-authenticator' : 'enrollment',
      language: event.notification.locale,
      recipient: event.notification.recipient,
      message_type: event.notification.delivery_method,
      text: event.notification.as_text,
      code: event.notification.code,
    };

    const response = await fetch(event.secret.SERVICE_URL, {
      method: 'POST',
      headers: {
        authorization: `Bearer ${event.secrets.TOKEN}`,
      },
      body: JSON.stringify(body),
    });

    console.log(response);
  }

  return;
};
```
