---
schema_version: "1"
id: 00b0e44b271d246655aac35c7f817792ce8be1c06f22fb060fd77c3077a3b1c0
title: Twilio Connector - Mule 4
collection: mulesoft
version: current
locale: ja-jp
portal_url: https://docs.salesforce.com/mulesoft/current/ja-jp/twilio-connector/3.0/index.md
canonical_url: https://docs.mulesoft.com/jp/twilio-connector/3.0/
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 9a3ffd4469d8ae1b9ee785bb1f5617aa0cb1ad0853006f10a29c3931e0f3a127
description: MuleSoft Documentation Site
release: "3.0"
latest: false
---
# Twilio Connector - Mule 4

サポートカテゴリ: [選択](https://www.mulesoft.com/legal/versioning-back-support-policy#anypoint-connectors)

Twilio Connector v3.0

Twilio 用 Anypoint Connector (Twilio Connector) は、クラウド通信 IaaS (Infrastructure as a Service) です。

Twilio プラットフォームは、テキストメッセージング、VoIP、および音声通話を行うための API として機能します。Twilio Connector は、Twilio テキストメッセージング API との接続を可能にします。

このコネクタは、テキストメッセージの送受信用の API を提供します。Twilio を使い始めるには、下記の手順に従って、SMS テキストメッセージを送信するための無料の Sandbox サービスにアクセスしてください。Anypoint Studio では、自分の API ログイン情報を使用して Twilio Connector を設定できます。

リリースノート: [Twilio Connector リリースノート](https://docs.mulesoft.com/jp/release-notes/connector/twilio-connector-release-notes-mule-4)  
Exchange: [Twilio Connector](https://www.mulesoft.com/exchange/com.mulesoft.connectors/mule-twilio-connector/)​

## [](#前提条件)前提条件

この情報を使用するには、Twilio、Mule Runtime Engine (Mule)、Anypoint Connector、Anypoint Studio、Mule の概念、Mule フローの要素、グローバル要素に精通している必要があります。

対象リソースへの接続をテストするには、ログイン情報が必要です。

ソフトウェアの要件および互換性情報については、「コネクタリリースノート」を参照してください。

Twilio Connector を使用するには、アクティブな Twilio.com アカウント (トライアル版または有料版) が必要です。Twilio アカウントを作成するには、Try Twilio (Twilio を試す) の Web サイト (​`https://www.twilio.com/try-twilio`​) にアクセスします。

## [](#pom-ファイルの連動関係の追加)POM ファイルの連動関係の追加

Apache Maven ​`pom.xml`​ ファイルは Anypoint Studio によって生成され、Mule アプリケーションの連動関係が含まれます。Mule アプリケーションを手動でコーディングする場合、次の XML スニペットを ​`pom.xml`​ ファイルに含めてこのコネクタにアクセスできるようにします:

```xml
<dependency>
  <groupId>com.mulesoft.connectors</groupId>
  <artifactId>mule-twilio-connector</artifactId>
  <version>x.x.x</version>
  <classifier>mule-plugin</classifier>
</dependency>
```

`x.x.x`​ を使用しているコネクタに対応するバージョンに置き換えます。

最新の ​`pom.xml`​ ファイル情報を取得する手順は、次のとおりです。

1. [Anypoint Exchange](https://www.mulesoft.com/exchange/)​ に移動します。
2. Exchange で、​**\[Login (ログイン)\]**​ をクリックし、Anypoint Platform のユーザー名とパスワードを指定します。
3. Exchange で、「​`twilio`​」を検索します。
4. コネクタを選択します。
5. 画面の右上付近にある ​**\[Dependency Snippets (連動関係スニペット)\]**​ をクリックします。

## [](#新しい-twilio-アカウントの作成)新しい Twilio アカウントの作成

1. Try Twilio (Twilio を試す) の Web サイト (​`https://www.twilio.com/try-twilio`​) にアクセスします。
2. サインアップして \[Start your free trial (無料トライアルを開始)\] をクリックします。
    
    無料の開発者アカウントでは、テキストメッセージを送信するための SMS に対応したスマートフォンでの確認が必要です。
3. スマートフォンの電話番号を入力するにように促されたら、入力します。指示に従って電話番号を確認します。自動テキストメッセージと認証コードが送られて来ます。
4. 認証コードを入力すると、Twilio のメイン画面が表示されます。
5. \[Account SID (アカウント SID)\] と \[Auth Token (認証トークン)\] の値 (\[Show (表示)\] をクリックすると表示されます) をメモし、ログイン情報を後で Anypoint Studio の Twilio Connector 設定メニューで使用するためにコピーしておきます。
    
    ヒント: Twilio の Web サイトから Anypoint Studio Connector 設定に項目をコピーする際には、前後にある余計な文字やスペースも一緒にコピーしてしまわないように注意してください。コピーして貼り付ける際に、前後の文字が含まれていないことを目で確認するのがよいでしょう。
6. 左上にある \[B\] をクリックし、\[Phone Numbers (電話番号)\] > \[Manage Numbers (番号の管理)\] をクリックします。
7. \[Get Started (使用開始)\] をクリックします。
8. \[Get your first Twilio phone number (最初の Twilio 電話番号を取得)\] をクリックします。Twilio が選択した電話番号が表示されます。この番号は後で使用しますので、コピーしておきます。

## [](#design-center-での接続)Design Center での接続

1. Design Center で \[Create (作成)\] をクリックして \[Mule Application (Mule アプリケーション)\] を選択します。
2. HTTP リスナーやスケジューラートリガーなどのトリガーをクリックします。
    
    ![トリガーオプション](/mulesoft/current/ja-jp/twilio-connector/3.0/_images/twilio-trigger.png)
3. コネクタの HTTP グローバル要素を作成するには、次の項目を設定します。
    
    ![HTTP リスナーの設定](/mulesoft/current/ja-jp/twilio-connector/3.0/_images/twilio-http-listener.png)
    
    <table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 30%;">
<col style="width: 70%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">項目</th>
<th class="tableblock halign-left valign-top">説明</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>Protocol (プロトコル)</strong></p></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>HTTP Connector のプロトコル。HTTP または HTTPS (セキュア) を選択できます。</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>Host (ホスト)</strong></p></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>Mule アプリケーションが要求をリスンする IP アドレス。</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>Port (ポート)</strong></p></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>Mule アプリケーションが要求をリスンするポートアドレス。</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>Base Path (ベースパス)</strong></p></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>Mule アプリケーションが要求をリスンするパス。</p>
</div></div></td>
</tr>
</tbody>
</table>
4. プラス記号を選択して、コンポーネントを追加します。
    
    ![コネクタの追加](/mulesoft/current/ja-jp/twilio-connector/3.0/_images/twilio-plus-sign.png)
5. Twilio Connector をコンポーネントとして選択します。
6. 操作を選択します。
    
    ![操作コネクタ](/mulesoft/current/ja-jp/twilio-connector/3.0/_images/twilio-select-operation-design.png)
7. コネクタのグローバル要素を設定します。
    
    ![コネクタの設定](/mulesoft/current/ja-jp/twilio-connector/3.0/_images/twilio-config-connector.png)
    
    <table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 30%;">
<col style="width: 70%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">項目</th>
<th class="tableblock halign-left valign-top">説明</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>Protocol (プロトコル)</strong></p></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>HTTP Connector のプロトコル。HTTP または HTTPS (セキュア) を選択できます。</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>Host (ホスト)</strong></p></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>Mule アプリケーションが要求をリスンする IP アドレス。</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>Port (ポート)</strong></p></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>Mule アプリケーションが要求をリスンするポートアドレス。</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>Base Path (ベースパス)</strong></p></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>Mule アプリケーションが要求をリスンするパス。</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>Username (ユーザー名)</strong></p></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>Twilio API にアクセスするためのユーザー名 (アカウント SID)。</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>Password (パスワード)</strong></p></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>Twilio API にアクセスするためのパスワード (認証トークン)。</p>
</div></div></td>
</tr>
</tbody>
</table>

## [](#studio-プロジェクトへのコネクタの追加)Studio プロジェクトへのコネクタの追加

Anypoint Studio には、Studio プロジェクトにコネクタを追加する 2 つの方法があります。Studio タスクバーの Exchange ボタンから追加するか、\[Mule Palette (Mule パレット)\] ビューから追加します。

### [](#exchange-を使用してコネクタを追加する)Exchange を使用してコネクタを追加する

1. Studio で Mule プロジェクトを作成します。
2. Studio タスクバーの左上にある Exchange アイコン ​**(X)**​ をクリックします。
3. Exchange で、​**\[Login (ログイン)\]**​ をクリックし、Anypoint Platform のユーザー名とパスワードを指定します。
4. Exchange で、「twilio」を検索します。
5. コネクタを選択して ​**\[Add to project (プロジェクトに追加)\]**​ をクリックします。
6. 画面の指示に従ってコネクタをインストールします。

### [](#studio-でコネクタに追加する)Studio でコネクタに追加する

1. Studio で Mule プロジェクトを作成します。
2. \[Mule Palette (Mule パレット)\] ビューで、​**\[(X) Search in Exchange ((X) Exchange 内を検索)\]**​ をクリックします。
3. **\[Add Modules to Project (モジュールをプロジェクトに追加)\]**​ で、検索項目に「twilio」と入力します。
4. **\[Available modules (使用可能なモジュール)\]**​ で、このコネクタの名前をクリックします。
5. **\[Add (追加)\]**​ をクリックします。
6. **\[Finish (完了)\]**​ をクリックします。

### [](#studio-で設定する)Studio で設定する

1. コネクタを Studio キャンバスにドラッグします。
2. Configure the global element for the connector.
    
    <table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 30%;">
<col style="width: 70%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">項目</th>
<th class="tableblock halign-left valign-top">説明</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>Protocol (プロトコル)</strong></p></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>HTTP Connector のプロトコル。HTTP または HTTPS (セキュア) を選択できます。</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>Host (ホスト)</strong></p></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>Mule アプリケーションが要求をリスンする IP アドレス。</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>Port (ポート)</strong></p></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>Mule アプリケーションが要求をリスンするポートアドレス。</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>Base Path (ベースパス)</strong></p></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>Mule アプリケーションが要求をリスンするパス。</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>Username (ユーザー名)</strong></p></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>Twilio API にアクセスするためのユーザー名 (アカウント SID)。</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>Password (パスワード)</strong></p></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>Twilio API にアクセスするためのパスワード (認証トークン)。</p>
</div></div></td>
</tr>
</tbody>
</table>
3. 操作を選択します。
    
    - Delete Media
    - Delete Message
    - Get Media
    - Get Media List
    - Get Message
    - Get Message List
    - Redact Message
    - Send Message

これらの項目では操作を指定できます。

<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 30%;">
<col style="width: 70%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">項目</th>
<th class="tableblock halign-left valign-top">説明</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>Account Sid (アカウント SID)</strong></p></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>このメッセージを送信したアカウントの一意の ID</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>Date Created (作成日付)</strong></p></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>リソースが作成された日付</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>Media Sid (メディア SID)</strong></p></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>メディアの一意の ID</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>Message Sid (メッセージ SID)</strong></p></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>メッセージの送信後に生成されたメッセージの一意の ID</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>Date Sent (送信日付)</strong></p></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>メッセージが Twilio から送信された日付 (RFC 2822 形式)</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>From (送信元)</strong></p></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>メッセージを送信した電話番号または送信者 ID (E.164 形式)</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>To (宛先)</strong></p></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>メッセージを受信した電話番号 (E.164 形式)</p>
</div></div></td>
</tr>
</tbody>
</table>

各形式についての詳細は、このドキュメントの最後にある「関連情報」セクションを参照してください。

## [](#例)例

次の例では、Mule アプリケーションから特定の電話番号にメッセージを送信してから編集しています。この例では、Twilio ログイン情報と、SMS が送信される電話番号の代わりに変数を使用しています。

### [](#事前手順)事前手順

次の手順に従って、項目値のプロパティプレースホルダーを使用します。

1. Studio で新しい Mule プロジェクトを作成します。
2. 次のプロパティを YAML または XML ファイルに追加します。
    
    ```text
    config.accountSid=<Your account SID>
    config.authToken=<Your authentication token>
    config.fromNumber=<The phone number from which the SMS is sent, as configured inside the Twilio instance>
    ```
3. プロジェクトの ​`src/main/resources`​ フォルダーにファイルを置きます。
4. [「プロパティ値のプロパティプレースホルダーの使用」](https://docs.mulesoft.com/connectors/introduction/intro-connector-configuration-overview#property-placeholders)​の説明に従って、コネクタ設定でこのファイルを参照します。

### [](#mule-アプリケーションを設定する)Mule アプリケーションを設定する

次の手順に従って、この例の Mule アプリケーションを設定します。

1. **\[HTTP Listener\]**​ 操作を Studio キャンバスにドラッグし、そのパスを ​`/send/{toNumber}`​ に設定します。
2. **Transform Message**​ コンポーネントを ​**\[Listener\]**​ の右にドラッグして、DataWeave を使用して Twilio Connector 用の入力を準備します。
    
    ```dataweave
    %dw 2.0
    output application/java
    ---
    {
        Body: "You are now subscribed!",
        From: p('fromNumber'),
        To: "+" ++ attributes.uriParams.toNumber as String default "my default value"
    }
    ```
3. Twilio の ​**\[Send Message\]**​ 操作を ​**Transform Message**​ コンポーネントの右にドラッグして、​**\[Account Sid (アカウント SID)\]**​ 項目を ​`${accountSid}`​ に設定します。
4. **Set Variable**​ コンポーネントを ​**Transform Message**​ コンポーネントの右にドラッグして、次の項目を設定します。
    
    - **\[Name (名前)\]**​ 項目を ​`messageSid`​ に設定します。
    - **\[Value (値)\]**​ 項目を \`#\[payload.sid\] に設定します。
5. **Transform Message**​ コンポーネントを ​**Set Variable**​ の右にドラッグして、​**Redact Message**​ 操作用の入力を作成します。
    
    ```dataweave
    %dw 2.0
    output application/java
    ---
    {
        Body: "",
        From: payload.from,
        To: payload.'to'
    }
    ```
6. Twilio の ​**\[Redact Message\]**​ 操作を ​**Transform Message**​ コンポーネントの右にドラッグして、次の項目を設定します。
    
    - **\[Account Sid (アカウント SID)\]**​ 項目を ​`${accountSid}`​ に設定します。
    - **\[Message Sid (メッセージ SID)\]**​ 項目を ​`#[messageSid]`​ (ステップ 5 で保存した変数) に設定します。
7. **Transform Message**​ コンポーネントを ​**\[Redact Message\]**​ の右にドラッグして、出力を ​`application/json`​ に設定します。
    
    ```dataweave
    %dw 2.0
    output application/json
    ---
    payload
    ```
8. アプリケーションを実行し、ブラウザーで ​`http://localhost:8081/send/{toNumber}`​ を開きます (​`toNumber`​ は Twilio から取得した電話番号に置き換えてください)。

## [](#関連情報)関連情報

- [Anypoint Connector の概要](https://docs.mulesoft.com/connectors/introduction/introduction-to-anypoint-connectors)
- [Exchange を使用したコネクタ、テンプレート、およびサンプルの検出](https://docs.mulesoft.com/connectors/introduction/intro-use-exchange)
- [Twilio API ドキュメント](https://www.twilio.com/docs/api/rest)
- [RFC 2822 形式](https://tools.ietf.org/html/rfc2822)
- [E.164 形式](https://en.wikipedia.org/wiki/E.164)
- [MuleSoft ヘルプセンター](https://help.mulesoft.com)