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

# 携帯へのメッセージ送信フロー

> Actionの携帯へのメッセージ送信フローとsend-phone-messageアクショントリガーについて学びます。これは、SMSを多要素認証（MFA）の要素として使用した場合、登録およびチャレンジプロセスで実行されます。

携帯へのメッセージ送信フローを使用すると、SMS/音声を[多要素認証（MFA）](/docs/ja-jp/secure/multi-factor-authentication)の要素として使用する際にコードを実行できます[カスタムプロバイダー](/docs/ja-jp/secure/multi-factor-authentication/multi-factor-authentication-factors/configure-sms-voice-notifications-mfa#custom-phone-messaging-providers)を使用してメッセージを送信する場合、このフローの`send-phone-message`トリガーを使用して、カスタムプロバイダーを設定する必要があります。

<Frame>
  <img src="https://mintcdn.com/docs-dev-docs-event-stream-action-templates/9Vac8_IYDB9MGlmx/docs/images/ja-jp/cdy7uua7fh8z/FSkVXDdknDJq1hsK08EYu/3337e5c67d6d699b401ee0efda88cd4e/send-phone-message-flow.png?fit=max&auto=format&n=9Vac8_IYDB9MGlmx&q=85&s=900a14a7609a037a78b212ed92c2afd9" alt="アクションの電話メッセージ送信フローの図。" width="681" height="126" data-path="docs/images/ja-jp/cdy7uua7fh8z/FSkVXDdknDJq1hsK08EYu/3337e5c67d6d699b401ee0efda88cd4e/send-phone-message-flow.png" />
</Frame>

このフロー内のアクションはブロッキング（同期的）であり、トリガーのプロセスの一部として実行されます。そのため、アクションが完了するまでAuth0パイプラインの他の部分の実行が停止されます。

## トリガー

### 携帯へのメッセージ送信

`send-phone-message`トリガーは、登録プロセスおよびチャレンジプロセスで実行されます（`event.message_options.action`）。また、ユニバーサルログインの新しいエクスペリエンスを使用する際、`音声`メッセージタイプの場合にも実行されます（`event.message_options.message_type === 'voice'`）。

#### リファレンス

* [イベントオブジェクト](/docs/ja-jp/customize/actions/explore-triggers/mfa-notifications-trigger/send-phone-message-event-object):送信されるメッセージや、チャレンジまたは登録されるユーザーに関するコンテキスト情報が提供されます。
* [APIオブジェクト](/docs/ja-jp/customize/actions/explore-triggers/mfa-notifications-trigger/send-phone-message-api-object):フローの動作を変更するためのメソッドが提供されます。

## 一般的なユースケース

### カスタムSMSプロバイダーを使用する

```javascript lines theme={null}
const AWS = require("aws-sdk");

/**
 * Handler that will be called during the execution of a SendPhoneMessage flow.
 *
 * @param {Event} event - Details about the user and the context in which they are logging in.
 */
exports.onExecuteSendPhoneMessage = async (event) => {
  const text = event.message_options.text;
  const recipient = event.message_options.recipient;

  const awsSNS = new AWS.SNS({
    apiVersion: "2010-03-31",
    region: event.secrets.AWS_REGION,
    credentials: new AWS.Credentials(event.secrets.AWS_ACCESS_KEY_ID, event.secrets.AWS_SECRET_ACCESS_KEY)
  });

  const params = { Message: text, PhoneNumber: recipient };

  return awsSNS
    .publish(params)
    .promise();
};
```

<Callout icon="file-lines" color="#0EA5E9" iconType="regular">
  このアクションが正常に動作するためには、`AWS_REGION`、`AWS_ACCESS_KEY_ID`、`AWS_SECRET_ACCESS_KEY`というシークレット名を含み、`aws-sdk`のNPMパッケージに依存しなければなりません。
</Callout>
