メインコンテンツにスキップ
You are viewing the Japanese site, but your language preference is set to English. Switch to English site →
Messaging

Programmable Messaging API

Twilioの単一APIが、SMS、MMS、WhatsAppメッセージの確実な送受信を実現します。

グローバルなメッセージング機能をアプリケーションに
組み込むために必要なものは数行のコードのみ

prog-message-api-chart.png

複数チャネルへの通知、アラート、マーケティングメッセージ送信は、単一APIのみで可能。電話番号、配信性、コンプライアンス、返信を管理するソフトウェアを搭載しています。

機能

多彩な機能を搭載。追加コーディングは
不要。

  • Node.js
  • Node.js
  • C#
  • PHP
  • Ruby
  • C#
  • PHP
  • Python
  • Ruby
  • Java
  • Python
  • Java
  • Python
  • Java
  • curl
  • curl

                    <span class="code-line"><span class="c1">// Download the Node helper library from twilio.com/docs/node/install</span>
</span><span class="code-line"><span class="c1">// These vars are your accountSid and authToken from twilio.com/user/account</span>
</span><span class="code-line"><span class="kd">const</span> <span class="nx">accountSid</span> <span class="o">=</span> <span class="s1">&#39;ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&#39;</span><span class="p">;</span>
</span><span class="code-line"><span class="kd">const</span> <span class="nx">authToken</span> <span class="o">=</span> <span class="s1">&#39;your_auth_token&#39;</span><span class="p">;</span>
</span><span class="code-line"><span class="kd">const</span> <span class="nx">client</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;twilio&#39;</span><span class="p">)(</span><span class="nx">accountSid</span><span class="p">,</span> <span class="nx">authToken</span><span class="p">);</span>
</span><span class="code-line">
</span><span class="code-line"><span class="nx">client</span><span class="p">.</span><span class="nx">messages</span><span class="p">.</span><span class="nx">create</span><span class="p">(</span>
</span><span class="code-line">  <span class="p">{</span>
</span><span class="code-line">    <span class="nx">body</span><span class="o">:</span> <span class="s1">&#39;All in the game, yo&#39;</span><span class="p">,</span>
</span><span class="code-line">    <span class="nx">to</span><span class="o">:</span> <span class="s1">&#39;+14108675310&#39;</span><span class="p">,</span>
</span><span class="code-line">    <span class="nx">from</span><span class="o">:</span> <span class="s1">&#39;+15005550006&#39;</span><span class="p">,</span>
</span><span class="code-line">  <span class="p">},</span>
</span><span class="code-line">  <span class="p">(</span><span class="nx">err</span><span class="p">,</span> <span class="nx">sms</span><span class="p">)</span> <span class="p">=&gt;</span> <span class="p">{</span>
</span><span class="code-line">    <span class="nx">process</span><span class="p">.</span><span class="nx">stdout</span><span class="p">.</span><span class="nx">write</span><span class="p">(</span><span class="nx">sms</span><span class="p">.</span><span class="nx">sid</span><span class="p">);</span>
</span><span class="code-line">  <span class="p">}</span>
</span><span class="code-line"><span class="p">);</span>
</span>
                

                    <span class="code-line"><span class="c1">// Download the Node helper library from twilio.com/docs/node/install</span>
</span><span class="code-line"><span class="c1">// These consts are your accountSid and authToken from https://www.twilio.com/console</span>
</span><span class="code-line"><span class="kd">const</span> <span class="nx">accountSid</span> <span class="o">=</span> <span class="s1">&#39;ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&#39;</span><span class="p">;</span>
</span><span class="code-line"><span class="kd">const</span> <span class="nx">authToken</span> <span class="o">=</span> <span class="s1">&#39;your_auth_token&#39;</span><span class="p">;</span>
</span><span class="code-line"><span class="kd">const</span> <span class="nx">client</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;twilio&#39;</span><span class="p">)(</span><span class="nx">accountSid</span><span class="p">,</span> <span class="nx">authToken</span><span class="p">);</span>
</span><span class="code-line">
</span><span class="code-line"><span class="nx">client</span><span class="p">.</span><span class="nx">messages</span>
</span><span class="code-line">  <span class="p">.</span><span class="nx">create</span><span class="p">({</span>
</span><span class="code-line">    <span class="nx">body</span><span class="o">:</span> <span class="s1">&#39;All in the game, yo&#39;</span><span class="p">,</span>
</span><span class="code-line">    <span class="nx">to</span><span class="o">:</span> <span class="s1">&#39;+14108675310&#39;</span><span class="p">,</span>
</span><span class="code-line">    <span class="nx">from</span><span class="o">:</span> <span class="s1">&#39;+15005550006&#39;</span><span class="p">,</span>
</span><span class="code-line">  <span class="p">})</span>
</span><span class="code-line">  <span class="p">.</span><span class="nx">then</span><span class="p">(</span><span class="nx">sms</span> <span class="p">=&gt;</span> <span class="nx">process</span><span class="p">.</span><span class="nx">stdout</span><span class="p">.</span><span class="nx">write</span><span class="p">(</span><span class="nx">sms</span><span class="p">.</span><span class="nx">sid</span><span class="p">));</span>
</span>
                

                    <span class="code-line"><span class="c1">// Download the twilio-csharp library from twilio.com/docs/csharp/install</span>
</span><span class="code-line"><span class="k">using</span> <span class="nn">System</span><span class="p">;</span>
</span><span class="code-line"><span class="k">using</span> <span class="nn">Twilio</span><span class="p">;</span>
</span><span class="code-line">
</span><span class="code-line"><span class="k">class</span> <span class="nc">Example</span>
</span><span class="code-line"><span class="p">{</span>
</span><span class="code-line">    <span class="k">static</span> <span class="k">void</span> <span class="nf">Main</span><span class="p">(</span><span class="kt">string</span><span class="p">[]</span> <span class="n">args</span><span class="p">)</span>
</span><span class="code-line">    <span class="p">{</span>
</span><span class="code-line">        <span class="c1">// Find your Account Sid and Auth Token at twilio.com/user/account</span>
</span><span class="code-line">        <span class="kt">string</span> <span class="n">AccountSid</span> <span class="p">=</span> <span class="s">&quot;ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&quot;</span><span class="p">;</span>
</span><span class="code-line">        <span class="kt">string</span> <span class="n">AuthToken</span> <span class="p">=</span> <span class="s">&quot;your_auth_token&quot;</span><span class="p">;</span>
</span><span class="code-line">        <span class="kt">var</span> <span class="n">twilio</span> <span class="p">=</span> <span class="k">new</span> <span class="n">TwilioRestClient</span><span class="p">(</span><span class="n">AccountSid</span><span class="p">,</span> <span class="n">AuthToken</span><span class="p">);</span>
</span><span class="code-line">
</span><span class="code-line">        <span class="kt">var</span> <span class="n">message</span> <span class="p">=</span> <span class="n">twilio</span><span class="p">.</span><span class="n">SendMessage</span><span class="p">(</span><span class="s">&quot;+15005550006&quot;</span><span class="p">,</span> <span class="s">&quot;+14108675310&quot;</span><span class="p">,</span> <span class="s">&quot;All in the game, yo&quot;</span><span class="p">);</span>
</span><span class="code-line">
</span><span class="code-line">        <span class="n">Console</span><span class="p">.</span><span class="n">WriteLine</span><span class="p">(</span><span class="n">message</span><span class="p">.</span><span class="n">Sid</span><span class="p">);</span>
</span><span class="code-line">    <span class="p">}</span>
</span><span class="code-line"><span class="p">}</span>
</span>
                

                    <span class="code-line"><span class="cp">&lt;?php</span>
</span><span class="code-line">
</span><span class="code-line"><span class="c1">// Get the PHP helper library from https://twilio.com/docs/libraries/php</span>
</span><span class="code-line"><span class="k">require_once</span> <span class="s1">&#39;/path/to/twilio-php/Services/Twilio.php&#39;</span><span class="p">;</span> <span class="c1">// Loads the library</span>
</span><span class="code-line">
</span><span class="code-line"><span class="c1">// Your Account Sid and Auth Token from twilio.com/user/account</span>
</span><span class="code-line"><span class="nv">$accountSid</span> <span class="o">=</span> <span class="s2">&quot;ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&quot;</span><span class="p">;</span>
</span><span class="code-line"><span class="nv">$authToken</span> <span class="o">=</span> <span class="s2">&quot;your_auth_token&quot;</span><span class="p">;</span>
</span><span class="code-line"><span class="nv">$client</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Services_Twilio</span><span class="p">(</span><span class="nv">$accountSid</span><span class="p">,</span> <span class="nv">$authToken</span><span class="p">);</span>
</span><span class="code-line">
</span><span class="code-line"><span class="nv">$message</span> <span class="o">=</span> <span class="nv">$client</span><span class="o">-&gt;</span><span class="na">account</span><span class="o">-&gt;</span><span class="na">messages</span><span class="o">-&gt;</span><span class="na">create</span><span class="p">(</span>
</span><span class="code-line">    <span class="k">array</span><span class="p">(</span>
</span><span class="code-line">        <span class="s1">&#39;To&#39;</span>   <span class="o">=&gt;</span> <span class="s1">&#39;+15005550006&#39;</span><span class="p">,</span>
</span><span class="code-line">        <span class="s1">&#39;From&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;+14108675310&#39;</span><span class="p">,</span>
</span><span class="code-line">        <span class="s1">&#39;Body&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;All in the game, yo&#39;</span>
</span><span class="code-line">    <span class="p">)</span>
</span><span class="code-line"><span class="p">);</span>
</span><span class="code-line">
</span><span class="code-line"><span class="k">echo</span> <span class="nv">$message</span><span class="o">-&gt;</span><span class="na">sid</span><span class="p">;</span>
</span>
                

                    <span class="code-line"><span class="c1"># Get twilio-ruby from twilio.com/docs/ruby/install</span>
</span><span class="code-line"><span class="nb">require</span> <span class="s1">&#39;twilio-ruby&#39;</span>
</span><span class="code-line">
</span><span class="code-line"><span class="c1"># Get your Account Sid and Auth Token from twilio.com/user/account</span>
</span><span class="code-line"><span class="n">account_sid</span> <span class="o">=</span> <span class="s1">&#39;ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&#39;</span>
</span><span class="code-line"><span class="n">auth_token</span> <span class="o">=</span> <span class="s1">&#39;your_auth_token&#39;</span>
</span><span class="code-line"><span class="vi">@client</span> <span class="o">=</span> <span class="no">Twilio</span><span class="o">::</span><span class="no">REST</span><span class="o">::</span><span class="no">Client</span><span class="o">.</span><span class="n">new</span><span class="p">(</span><span class="n">account_sid</span><span class="p">,</span> <span class="n">auth_token</span><span class="p">)</span>
</span><span class="code-line">
</span><span class="code-line"><span class="n">message</span> <span class="o">=</span> <span class="vi">@client</span><span class="o">.</span><span class="n">account</span><span class="o">.</span><span class="n">messages</span><span class="o">.</span><span class="n">create</span><span class="p">(</span>
</span><span class="code-line">  <span class="ss">body</span><span class="p">:</span> <span class="s1">&#39;All in the game, yo&#39;</span><span class="p">,</span>
</span><span class="code-line">  <span class="ss">to</span><span class="p">:</span> <span class="s1">&#39;+14108675310&#39;</span><span class="p">,</span>
</span><span class="code-line">  <span class="ss">from</span><span class="p">:</span> <span class="s1">&#39;+15005550006&#39;</span>
</span><span class="code-line"><span class="p">)</span>
</span><span class="code-line">
</span><span class="code-line"><span class="nb">puts</span> <span class="n">message</span><span class="o">.</span><span class="n">sid</span>
</span>
                

                    <span class="code-line"><span class="c1">// Download the twilio-csharp library from twilio.com/docs/libraries/csharp</span>
</span><span class="code-line"><span class="k">using</span> <span class="nn">System</span><span class="p">;</span>
</span><span class="code-line"><span class="k">using</span> <span class="nn">Twilio</span><span class="p">;</span>
</span><span class="code-line"><span class="k">using</span> <span class="nn">Twilio.Rest.Api.V2010.Account</span><span class="p">;</span>
</span><span class="code-line"><span class="k">using</span> <span class="nn">Twilio.Types</span><span class="p">;</span>
</span><span class="code-line">
</span><span class="code-line"><span class="k">class</span> <span class="nc">Example</span>
</span><span class="code-line"><span class="p">{</span>
</span><span class="code-line">    <span class="k">static</span> <span class="k">void</span> <span class="nf">Main</span><span class="p">(</span><span class="kt">string</span><span class="p">[]</span> <span class="n">args</span><span class="p">)</span>
</span><span class="code-line">    <span class="p">{</span>
</span><span class="code-line">        <span class="c1">// Find your Account Sid and Auth Token at twilio.com/console</span>
</span><span class="code-line">        <span class="k">const</span> <span class="kt">string</span> <span class="n">accountSid</span> <span class="p">=</span> <span class="s">&quot;ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&quot;</span><span class="p">;</span>
</span><span class="code-line">        <span class="k">const</span> <span class="kt">string</span> <span class="n">authToken</span> <span class="p">=</span> <span class="s">&quot;your_auth_token&quot;</span><span class="p">;</span>
</span><span class="code-line">        <span class="n">TwilioClient</span><span class="p">.</span><span class="n">Init</span><span class="p">(</span><span class="n">accountSid</span><span class="p">,</span> <span class="n">authToken</span><span class="p">);</span>
</span><span class="code-line">
</span><span class="code-line">        <span class="kt">var</span> <span class="n">to</span> <span class="p">=</span> <span class="k">new</span> <span class="n">PhoneNumber</span><span class="p">(</span><span class="s">&quot;+15005550006&quot;</span><span class="p">);</span>
</span><span class="code-line">        <span class="kt">var</span> <span class="n">message</span> <span class="p">=</span> <span class="n">MessageResource</span><span class="p">.</span><span class="n">Create</span><span class="p">(</span>
</span><span class="code-line">            <span class="n">to</span><span class="p">,</span>
</span><span class="code-line">            <span class="k">from</span><span class="p">:</span> <span class="k">new</span> <span class="n">PhoneNumber</span><span class="p">(</span><span class="s">&quot;+14108675310&quot;</span><span class="p">),</span>
</span><span class="code-line">            <span class="n">body</span><span class="p">:</span> <span class="s">&quot;All in the game, yo&quot;</span><span class="p">);</span>
</span><span class="code-line">
</span><span class="code-line">        <span class="n">Console</span><span class="p">.</span><span class="n">WriteLine</span><span class="p">(</span><span class="n">message</span><span class="p">.</span><span class="n">Sid</span><span class="p">);</span>
</span><span class="code-line">    <span class="p">}</span>
</span><span class="code-line"><span class="p">}</span>
</span>
                

                    <span class="code-line"><span class="cp">&lt;?php</span>
</span><span class="code-line"><span class="c1">// Get the PHP helper library from https://twilio.com/docs/libraries/php</span>
</span><span class="code-line"><span class="k">require_once</span> <span class="s1">&#39;/path/to/vendor/autoload.php&#39;</span><span class="p">;</span> <span class="c1">// Loads the library</span>
</span><span class="code-line"><span class="k">use</span> <span class="nx">Twilio\Rest\Client</span><span class="p">;</span>
</span><span class="code-line">
</span><span class="code-line"><span class="c1">// Your Account Sid and Auth Token from twilio.com/user/account</span>
</span><span class="code-line"><span class="nv">$sid</span> <span class="o">=</span> <span class="s2">&quot;ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&quot;</span><span class="p">;</span>
</span><span class="code-line"><span class="nv">$token</span> <span class="o">=</span> <span class="s2">&quot;your_auth_token&quot;</span><span class="p">;</span>
</span><span class="code-line"><span class="nv">$client</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Client</span><span class="p">(</span><span class="nv">$sid</span><span class="p">,</span> <span class="nv">$token</span><span class="p">);</span>
</span><span class="code-line">
</span><span class="code-line"><span class="nv">$sms</span> <span class="o">=</span> <span class="nv">$client</span><span class="o">-&gt;</span><span class="na">messages</span><span class="o">-&gt;</span><span class="na">create</span><span class="p">(</span>
</span><span class="code-line">    <span class="s2">&quot;+14108675310&quot;</span><span class="p">,</span>
</span><span class="code-line">    <span class="k">array</span><span class="p">(</span>
</span><span class="code-line">        <span class="s2">&quot;from&quot;</span> <span class="o">=&gt;</span> <span class="s2">&quot;+15005550006&quot;</span><span class="p">,</span>
</span><span class="code-line">        <span class="s2">&quot;body&quot;</span> <span class="o">=&gt;</span> <span class="s2">&quot;All in the game, yo&quot;</span>
</span><span class="code-line">    <span class="p">)</span>
</span><span class="code-line"><span class="p">);</span>
</span><span class="code-line">
</span><span class="code-line"><span class="k">echo</span> <span class="nv">$sms</span><span class="o">-&gt;</span><span class="na">sid</span><span class="p">;</span>
</span>
                

                    <span class="code-line"><span class="c1"># Download the Python helper library from twilio.com/docs/python/install</span>
</span><span class="code-line"><span class="kn">from</span> <span class="nn">twilio.rest</span> <span class="kn">import</span> <span class="n">TwilioRestClient</span>
</span><span class="code-line">
</span><span class="code-line"><span class="c1"># Your Account Sid and Auth Token from twilio.com/user/account</span>
</span><span class="code-line"><span class="n">account_sid</span> <span class="o">=</span> <span class="s2">&quot;ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&quot;</span>
</span><span class="code-line"><span class="n">auth_token</span> <span class="o">=</span> <span class="s2">&quot;your_auth_token&quot;</span>
</span><span class="code-line"><span class="n">client</span> <span class="o">=</span> <span class="n">TwilioRestClient</span><span class="p">(</span><span class="n">account_sid</span><span class="p">,</span> <span class="n">auth_token</span><span class="p">)</span>
</span><span class="code-line">
</span><span class="code-line"><span class="n">message</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">messages</span><span class="o">.</span><span class="n">create</span><span class="p">(</span>
</span><span class="code-line">    <span class="n">body</span><span class="o">=</span><span class="s2">&quot;All in the game, yo&quot;</span><span class="p">,</span> <span class="n">to</span><span class="o">=</span><span class="s2">&quot;+14108675310&quot;</span><span class="p">,</span> <span class="n">from_</span><span class="o">=</span><span class="s2">&quot;+15005550006&quot;</span>
</span><span class="code-line"><span class="p">)</span>
</span><span class="code-line">
</span><span class="code-line"><span class="nb">print</span><span class="p">(</span><span class="n">message</span><span class="o">.</span><span class="n">sid</span><span class="p">)</span>
</span>
                

                    <span class="code-line"><span class="c1"># Get twilio-ruby from twilio.com/docs/ruby/install</span>
</span><span class="code-line"><span class="nb">require</span> <span class="s1">&#39;twilio-ruby&#39;</span>
</span><span class="code-line">
</span><span class="code-line"><span class="c1"># Get your Account SID and Auth Token from twilio.com/console</span>
</span><span class="code-line"><span class="n">account_sid</span> <span class="o">=</span> <span class="s1">&#39;ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&#39;</span>
</span><span class="code-line"><span class="n">auth_token</span> <span class="o">=</span> <span class="s1">&#39;your_auth_token&#39;</span>
</span><span class="code-line"><span class="vi">@client</span> <span class="o">=</span> <span class="no">Twilio</span><span class="o">::</span><span class="no">REST</span><span class="o">::</span><span class="no">Client</span><span class="o">.</span><span class="n">new</span><span class="p">(</span><span class="n">account_sid</span><span class="p">,</span> <span class="n">auth_token</span><span class="p">)</span>
</span><span class="code-line">
</span><span class="code-line"><span class="n">message</span> <span class="o">=</span> <span class="vi">@client</span><span class="o">.</span><span class="n">messages</span><span class="o">.</span><span class="n">create</span><span class="p">(</span>
</span><span class="code-line">  <span class="ss">body</span><span class="p">:</span> <span class="s1">&#39;All in the game, yo&#39;</span><span class="p">,</span>
</span><span class="code-line">  <span class="ss">to</span><span class="p">:</span> <span class="s1">&#39;+14108675310&#39;</span><span class="p">,</span>
</span><span class="code-line">  <span class="ss">from</span><span class="p">:</span> <span class="s1">&#39;+15005550006&#39;</span>
</span><span class="code-line"><span class="p">)</span>
</span><span class="code-line">
</span><span class="code-line"><span class="nb">puts</span> <span class="n">message</span><span class="o">.</span><span class="n">sid</span>
</span>
                

                    <span class="code-line"><span class="c1">// Install the Java helper library from twilio.com/docs/java/install</span>
</span><span class="code-line"><span class="kn">import</span> <span class="nn">com.twilio.sdk.TwilioRestClient</span><span class="p">;</span>
</span><span class="code-line"><span class="kn">import</span> <span class="nn">com.twilio.sdk.TwilioRestException</span><span class="p">;</span>
</span><span class="code-line"><span class="kn">import</span> <span class="nn">com.twilio.sdk.resource.factory.MessageFactory</span><span class="p">;</span>
</span><span class="code-line"><span class="kn">import</span> <span class="nn">com.twilio.sdk.resource.instance.Message</span><span class="p">;</span>
</span><span class="code-line"><span class="kn">import</span> <span class="nn">org.apache.http.NameValuePair</span><span class="p">;</span>
</span><span class="code-line"><span class="kn">import</span> <span class="nn">org.apache.http.message.BasicNameValuePair</span><span class="p">;</span>
</span><span class="code-line">
</span><span class="code-line"><span class="kn">import</span> <span class="nn">java.util.ArrayList</span><span class="p">;</span>
</span><span class="code-line"><span class="kn">import</span> <span class="nn">java.util.List</span><span class="p">;</span>
</span><span class="code-line">
</span><span class="code-line"><span class="kd">public</span> <span class="kd">class</span> <span class="nc">Example</span> <span class="p">{</span>
</span><span class="code-line">
</span><span class="code-line">    <span class="c1">// Find your Account Sid and Token at twilio.com/user/account</span>
</span><span class="code-line">    <span class="kd">public</span> <span class="kd">static</span> <span class="kd">final</span> <span class="n">String</span> <span class="n">ACCOUNT_SID</span> <span class="o">=</span> <span class="s">&quot;ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&quot;</span><span class="p">;</span>
</span><span class="code-line">    <span class="kd">public</span> <span class="kd">static</span> <span class="kd">final</span> <span class="n">String</span> <span class="n">AUTH_TOKEN</span> <span class="o">=</span> <span class="s">&quot;your_auth_token&quot;</span><span class="p">;</span>
</span><span class="code-line">
</span><span class="code-line">    <span class="kd">public</span> <span class="kd">static</span> <span class="kt">void</span> <span class="nf">main</span><span class="p">(</span><span class="n">String</span><span class="o">[]</span> <span class="n">args</span><span class="p">)</span> <span class="kd">throws</span> <span class="n">TwilioRestException</span> <span class="p">{</span>
</span><span class="code-line">        <span class="n">TwilioRestClient</span> <span class="n">client</span> <span class="o">=</span> <span class="k">new</span> <span class="n">TwilioRestClient</span><span class="p">(</span><span class="n">ACCOUNT_SID</span><span class="p">,</span> <span class="n">AUTH_TOKEN</span><span class="p">);</span>
</span><span class="code-line">
</span><span class="code-line">        <span class="c1">// Build a filter for search</span>
</span><span class="code-line">        <span class="n">List</span><span class="o">&lt;</span><span class="n">NameValuePair</span><span class="o">&gt;</span> <span class="n">params</span> <span class="o">=</span> <span class="k">new</span> <span class="n">ArrayList</span><span class="o">&lt;&gt;</span><span class="p">();</span>
</span><span class="code-line">        <span class="n">params</span><span class="p">.</span><span class="na">add</span><span class="p">(</span><span class="k">new</span> <span class="n">BasicNameValuePair</span><span class="p">(</span><span class="s">&quot;Body&quot;</span><span class="p">,</span> <span class="s">&quot;All in the game, yo&quot;</span><span class="p">));</span>
</span><span class="code-line">        <span class="n">params</span><span class="p">.</span><span class="na">add</span><span class="p">(</span><span class="k">new</span> <span class="n">BasicNameValuePair</span><span class="p">(</span><span class="s">&quot;To&quot;</span><span class="p">,</span> <span class="s">&quot;+14108675310&quot;</span><span class="p">));</span>
</span><span class="code-line">        <span class="n">params</span><span class="p">.</span><span class="na">add</span><span class="p">(</span><span class="k">new</span> <span class="n">BasicNameValuePair</span><span class="p">(</span><span class="s">&quot;From&quot;</span><span class="p">,</span> <span class="s">&quot;+15005550006&quot;</span><span class="p">));</span>
</span><span class="code-line">
</span><span class="code-line">        <span class="n">MessageFactory</span> <span class="n">messageFactory</span> <span class="o">=</span> <span class="n">client</span><span class="p">.</span><span class="na">getAccount</span><span class="p">().</span><span class="na">getMessageFactory</span><span class="p">();</span>
</span><span class="code-line">        <span class="n">Message</span> <span class="n">message</span> <span class="o">=</span> <span class="n">messageFactory</span><span class="p">.</span><span class="na">create</span><span class="p">(</span><span class="n">params</span><span class="p">);</span>
</span><span class="code-line">        <span class="n">System</span><span class="p">.</span><span class="na">out</span><span class="p">.</span><span class="na">println</span><span class="p">(</span><span class="n">message</span><span class="p">.</span><span class="na">getSid</span><span class="p">());</span>
</span><span class="code-line">    <span class="p">}</span>
</span><span class="code-line"><span class="p">}</span>
</span>
                

                    <span class="code-line"><span class="c1"># Download the Python helper library from twilio.com/docs/python/install</span>
</span><span class="code-line"><span class="kn">from</span> <span class="nn">twilio.rest</span> <span class="kn">import</span> <span class="n">Client</span>
</span><span class="code-line">
</span><span class="code-line"><span class="c1"># Your Account Sid and Auth Token from twilio.com/user/account</span>
</span><span class="code-line"><span class="n">account_sid</span> <span class="o">=</span> <span class="s2">&quot;ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&quot;</span>
</span><span class="code-line"><span class="n">auth_token</span> <span class="o">=</span> <span class="s2">&quot;your_auth_token&quot;</span>
</span><span class="code-line">
</span><span class="code-line"><span class="n">client</span> <span class="o">=</span> <span class="n">Client</span><span class="p">(</span><span class="n">account_sid</span><span class="p">,</span> <span class="n">auth_token</span><span class="p">)</span>
</span><span class="code-line">
</span><span class="code-line"><span class="n">message</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">messages</span><span class="o">.</span><span class="n">create</span><span class="p">(</span>
</span><span class="code-line">        <span class="n">body</span><span class="o">=</span><span class="s2">&quot;All in the game, yo&quot;</span><span class="p">,</span>
</span><span class="code-line">        <span class="n">to</span><span class="o">=</span><span class="s2">&quot;+5571981265131&quot;</span><span class="p">,</span>
</span><span class="code-line">        <span class="n">from_</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">)</span>
</span><span class="code-line">
</span><span class="code-line"><span class="nb">print</span><span class="p">(</span><span class="n">message</span><span class="o">.</span><span class="n">sid</span><span class="p">)</span>
</span>
                

                    <span class="code-line"><span class="c1">// Install the Java helper library from twilio.com/docs/java/install</span>
</span><span class="code-line">
</span><span class="code-line"><span class="kn">import</span> <span class="nn">com.twilio.Twilio</span><span class="p">;</span>
</span><span class="code-line"><span class="kn">import</span> <span class="nn">com.twilio.rest.api.v2010.account.Message</span><span class="p">;</span>
</span><span class="code-line"><span class="kn">import</span> <span class="nn">com.twilio.type.PhoneNumber</span><span class="p">;</span>
</span><span class="code-line">
</span><span class="code-line"><span class="kd">public</span> <span class="kd">class</span> <span class="nc">Example</span> <span class="p">{</span>
</span><span class="code-line">  <span class="c1">// Find your Account Sid and Token at twilio.com/user/account</span>
</span><span class="code-line">  <span class="kd">public</span> <span class="kd">static</span> <span class="kd">final</span> <span class="n">String</span> <span class="n">ACCOUNT_SID</span> <span class="o">=</span> <span class="s">&quot;ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&quot;</span><span class="p">;</span>
</span><span class="code-line">  <span class="kd">public</span> <span class="kd">static</span> <span class="kd">final</span> <span class="n">String</span> <span class="n">AUTH_TOKEN</span> <span class="o">=</span> <span class="s">&quot;your_auth_token&quot;</span><span class="p">;</span>
</span><span class="code-line">
</span><span class="code-line">  <span class="kd">public</span> <span class="kd">static</span> <span class="kt">void</span> <span class="nf">main</span><span class="p">(</span><span class="n">String</span><span class="o">[]</span> <span class="n">args</span><span class="p">)</span> <span class="p">{</span>
</span><span class="code-line">    <span class="n">Twilio</span><span class="p">.</span><span class="na">init</span><span class="p">(</span><span class="n">ACCOUNT_SID</span><span class="p">,</span> <span class="n">AUTH_TOKEN</span><span class="p">);</span>
</span><span class="code-line">
</span><span class="code-line">    <span class="n">Message</span> <span class="n">sms</span> <span class="o">=</span> <span class="n">Message</span><span class="p">.</span><span class="na">creator</span><span class="p">(</span><span class="k">new</span> <span class="n">PhoneNumber</span><span class="p">(</span><span class="s">&quot;+14108675310&quot;</span><span class="p">),</span> <span class="k">new</span> <span class="n">PhoneNumber</span><span class="p">(</span><span class="s">&quot;15005550006&quot;</span><span class="p">),</span>
</span><span class="code-line">        <span class="s">&quot;All in the game, yo&quot;</span><span class="p">).</span><span class="na">create</span><span class="p">();</span>
</span><span class="code-line">
</span><span class="code-line">    <span class="n">System</span><span class="p">.</span><span class="na">out</span><span class="p">.</span><span class="na">println</span><span class="p">(</span><span class="n">sms</span><span class="p">.</span><span class="na">getSid</span><span class="p">());</span>
</span><span class="code-line">  <span class="p">}</span>
</span><span class="code-line"><span class="p">}</span>
</span>
                

                    <span class="code-line"><span class="c1"># Download the Python helper library from twilio.com/docs/python/install</span>
</span><span class="code-line"><span class="kn">import</span> <span class="nn">os</span>
</span><span class="code-line"><span class="kn">from</span> <span class="nn">twilio.rest</span> <span class="kn">import</span> <span class="n">Client</span>
</span><span class="code-line">
</span><span class="code-line"><span class="c1"># Your Account Sid and Auth Token from twilio.com/user/account</span>
</span><span class="code-line"><span class="c1"># To set up environmental variables, see http://twil.io/secure</span>
</span><span class="code-line"><span class="n">account_sid</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s1">&#39;TWILIO_ACCOUNT_SID&#39;</span><span class="p">]</span>
</span><span class="code-line"><span class="n">auth_token</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s1">&#39;TWILIO_AUTH_TOKEN&#39;</span><span class="p">]</span>
</span><span class="code-line">
</span><span class="code-line"><span class="n">client</span> <span class="o">=</span> <span class="n">Client</span><span class="p">(</span><span class="n">account_sid</span><span class="p">,</span> <span class="n">auth_token</span><span class="p">)</span>
</span><span class="code-line">
</span><span class="code-line"><span class="n">message</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">messages</span><span class="o">.</span><span class="n">create</span><span class="p">(</span>
</span><span class="code-line">    <span class="n">body</span><span class="o">=</span><span class="s2">&quot;All in the game, yo&quot;</span><span class="p">,</span> <span class="n">to</span><span class="o">=</span><span class="s2">&quot;+5571981265131&quot;</span><span class="p">,</span> <span class="n">from_</span><span class="o">=</span><span class="s2">&quot;&quot;</span>
</span><span class="code-line"><span class="p">)</span>
</span><span class="code-line">
</span><span class="code-line"><span class="nb">print</span><span class="p">(</span><span class="n">message</span><span class="o">.</span><span class="n">sid</span><span class="p">)</span>
</span>
                

                    <span class="code-line"><span class="c1">// Install the Java helper library from twilio.com/docs/java/install</span>
</span><span class="code-line">
</span><span class="code-line"><span class="kn">import</span> <span class="nn">com.twilio.Twilio</span><span class="p">;</span>
</span><span class="code-line"><span class="kn">import</span> <span class="nn">com.twilio.rest.api.v2010.account.Message</span><span class="p">;</span>
</span><span class="code-line"><span class="kn">import</span> <span class="nn">com.twilio.type.PhoneNumber</span><span class="p">;</span>
</span><span class="code-line">
</span><span class="code-line"><span class="kd">public</span> <span class="kd">class</span> <span class="nc">Example</span> <span class="p">{</span>
</span><span class="code-line">  <span class="c1">// Get your Account SID and Auth Token from https://twilio.com/console</span>
</span><span class="code-line">  <span class="c1">// To set up environment variables, see http://twil.io/secure</span>
</span><span class="code-line">  <span class="kd">public</span> <span class="kd">static</span> <span class="kd">final</span> <span class="n">String</span> <span class="n">ACCOUNT_SID</span> <span class="o">=</span> <span class="n">System</span><span class="p">.</span><span class="na">getenv</span><span class="p">(</span><span class="s">&quot;TWILIO_ACCOUNT_SID&quot;</span><span class="p">);</span>
</span><span class="code-line">  <span class="kd">public</span> <span class="kd">static</span> <span class="kd">final</span> <span class="n">String</span> <span class="n">AUTH_TOKEN</span> <span class="o">=</span> <span class="n">System</span><span class="p">.</span><span class="na">getenv</span><span class="p">(</span><span class="s">&quot;TWILIO_AUTH_TOKEN&quot;</span><span class="p">);</span>
</span><span class="code-line">
</span><span class="code-line">  <span class="kd">public</span> <span class="kd">static</span> <span class="kt">void</span> <span class="nf">main</span><span class="p">(</span><span class="n">String</span><span class="o">[]</span> <span class="n">args</span><span class="p">)</span> <span class="p">{</span>
</span><span class="code-line">    <span class="n">Twilio</span><span class="p">.</span><span class="na">init</span><span class="p">(</span><span class="n">ACCOUNT_SID</span><span class="p">,</span> <span class="n">AUTH_TOKEN</span><span class="p">);</span>
</span><span class="code-line">
</span><span class="code-line">    <span class="n">Message</span> <span class="n">sms</span> <span class="o">=</span> <span class="n">Message</span><span class="p">.</span><span class="na">creator</span><span class="p">(</span><span class="k">new</span> <span class="n">PhoneNumber</span><span class="p">(</span><span class="s">&quot;+14108675310&quot;</span><span class="p">),</span> <span class="k">new</span> <span class="n">PhoneNumber</span><span class="p">(</span><span class="s">&quot;15005550006&quot;</span><span class="p">),</span>
</span><span class="code-line">        <span class="s">&quot;All in the game, yo&quot;</span><span class="p">).</span><span class="na">create</span><span class="p">();</span>
</span><span class="code-line">
</span><span class="code-line">    <span class="n">System</span><span class="p">.</span><span class="na">out</span><span class="p">.</span><span class="na">println</span><span class="p">(</span><span class="n">sms</span><span class="p">.</span><span class="na">getSid</span><span class="p">());</span>
</span><span class="code-line">  <span class="p">}</span>
</span><span class="code-line"><span class="p">}</span>
</span>
                

                    <span class="code-line">curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages <span class="se">\</span>
</span><span class="code-line">    -d <span class="s2">&quot;Body=All%20in%20the%20game%2C%20yo&quot;</span> <span class="se">\</span>
</span><span class="code-line">    -d <span class="s2">&quot;To=%2B14108675310&quot;</span> <span class="se">\</span>
</span><span class="code-line">    -d <span class="s2">&quot;From=%2B15005550006&quot;</span> <span class="se">\</span>
</span><span class="code-line">    -u <span class="s1">&#39;ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token&#39;</span>
</span>
                

                    <span class="code-line">curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages.json <span class="se">\</span>
</span><span class="code-line">    -d <span class="s2">&quot;Body=All%20in%20the%20game%2C%20yo&quot;</span> <span class="se">\</span>
</span><span class="code-line">    -d <span class="s2">&quot;To=%2B14108675310&quot;</span> <span class="se">\</span>
</span><span class="code-line">    -d <span class="s2">&quot;From=%2B15005550006&quot;</span> <span class="se">\</span>
</span><span class="code-line">    -u <span class="s1">&#39;ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token&#39;</span>
</span>
                

大規模配信のコンプライアンス対応も標準装備

  • 大量のメッセージをグローバルに送信:ショートコード、英数字の送信者ID、高スループットのフリーダイヤル番号を選択
  • 高度なオプトアウト機能:各国の法規制や言語にあわせ、オプトインやオプトアウトをコンソールでカスタマイズ
  • メッセージのマスキング:電話番号の下4桁とメッセージ本文をマスキングし、顧客の機密データを保護
  • 英数字の送信者IDの警告:英数字の送信者IDの事前登録が必要な場合、送信時に自動でアラートを検出
  • Node.js
  • C#
  • PHP
  • Ruby
  • Python
  • Java
  • Python
  • Java
  • curl

                    <span class="code-line"><span class="c1">// Download the Node helper library from twilio.com/docs/libraries/node</span>
</span><span class="code-line"><span class="c1">// These consts are your accountSid and authToken from https://www.twilio.com/console</span>
</span><span class="code-line"><span class="kd">const</span> <span class="nx">accountSid</span> <span class="o">=</span> <span class="s1">&#39;ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&#39;</span><span class="p">;</span>
</span><span class="code-line"><span class="kd">const</span> <span class="nx">authToken</span> <span class="o">=</span> <span class="s1">&#39;your_auth_token&#39;</span><span class="p">;</span>
</span><span class="code-line">
</span><span class="code-line"><span class="kd">const</span> <span class="nx">client</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;twilio&#39;</span><span class="p">)(</span><span class="nx">accountSid</span><span class="p">,</span> <span class="nx">authToken</span><span class="p">);</span>
</span><span class="code-line">
</span><span class="code-line"><span class="kd">const</span> <span class="nx">opts</span> <span class="o">=</span> <span class="p">{</span>
</span><span class="code-line">  <span class="nx">friendlyName</span><span class="o">:</span> <span class="s1">&#39;My First Service&#39;</span><span class="p">,</span>
</span><span class="code-line">  <span class="nx">statusCallback</span><span class="o">:</span> <span class="s1">&#39;http://requestb.in/1234abcd&#39;</span><span class="p">,</span>
</span><span class="code-line"><span class="p">};</span>
</span><span class="code-line">
</span><span class="code-line"><span class="nx">client</span><span class="p">.</span><span class="nx">messaging</span><span class="p">.</span><span class="nx">services</span>
</span><span class="code-line">  <span class="p">.</span><span class="nx">create</span><span class="p">(</span><span class="nx">opts</span><span class="p">)</span>
</span><span class="code-line">  <span class="p">.</span><span class="nx">then</span><span class="p">(</span><span class="nx">response</span> <span class="p">=&gt;</span> <span class="p">{</span>
</span><span class="code-line">    <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">response</span><span class="p">);</span>
</span><span class="code-line">  <span class="p">})</span>
</span><span class="code-line">  <span class="p">.</span><span class="k">catch</span><span class="p">(</span><span class="nx">error</span> <span class="p">=&gt;</span> <span class="p">{</span>
</span><span class="code-line">    <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">error</span><span class="p">);</span>
</span><span class="code-line">  <span class="p">});</span>
</span>
                

                    <span class="code-line"><span class="c1">// Download the twilio-csharp library from twilio.com/docs/libraries/csharp</span>
</span><span class="code-line"><span class="k">using</span> <span class="nn">System</span><span class="p">;</span>
</span><span class="code-line"><span class="k">using</span> <span class="nn">Twilio</span><span class="p">;</span>
</span><span class="code-line"><span class="k">using</span> <span class="nn">Twilio.Rest.Messaging.V1</span><span class="p">;</span>
</span><span class="code-line">
</span><span class="code-line">
</span><span class="code-line"><span class="k">class</span> <span class="nc">Example</span>
</span><span class="code-line"><span class="p">{</span>
</span><span class="code-line">    <span class="k">static</span> <span class="k">void</span> <span class="nf">Main</span> <span class="p">(</span><span class="kt">string</span><span class="p">[]</span> <span class="n">args</span><span class="p">)</span>
</span><span class="code-line">    <span class="p">{</span>
</span><span class="code-line">      <span class="c1">// Find your Account SID and Auth Token at twilio.com/console</span>
</span><span class="code-line">      <span class="k">const</span> <span class="kt">string</span> <span class="n">accountSid</span> <span class="p">=</span> <span class="s">&quot;ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&quot;</span><span class="p">;</span>
</span><span class="code-line">      <span class="k">const</span> <span class="kt">string</span> <span class="n">authToken</span> <span class="p">=</span> <span class="s">&quot;your_auth_token&quot;</span><span class="p">;</span>
</span><span class="code-line">      <span class="k">const</span> <span class="kt">string</span> <span class="n">serviceFriendlyName</span> <span class="p">=</span> <span class="s">&quot;My First Service&quot;</span><span class="p">;</span>
</span><span class="code-line">
</span><span class="code-line">      <span class="n">TwilioClient</span><span class="p">.</span><span class="n">Init</span><span class="p">(</span><span class="n">accountSid</span><span class="p">,</span> <span class="n">authToken</span><span class="p">);</span>
</span><span class="code-line">
</span><span class="code-line">      <span class="kt">var</span> <span class="n">service</span> <span class="p">=</span> <span class="n">ServiceResource</span><span class="p">.</span><span class="n">Create</span><span class="p">(</span><span class="n">serviceFriendlyName</span><span class="p">);</span>
</span><span class="code-line">
</span><span class="code-line">      <span class="n">Console</span><span class="p">.</span><span class="n">WriteLine</span><span class="p">(</span><span class="n">service</span><span class="p">.</span><span class="n">Sid</span><span class="p">);</span>
</span><span class="code-line">    <span class="p">}</span>
</span><span class="code-line"><span class="p">}</span>
</span>
                

                    <span class="code-line"><span class="cp">&lt;?php</span>
</span><span class="code-line"><span class="c1">// Get the PHP helper library from https://twilio.com/docs/libraries/php</span>
</span><span class="code-line"><span class="k">require_once</span> <span class="s1">&#39;/path/to/vendor/autoload.php&#39;</span><span class="p">;</span> <span class="c1">// Loads the library</span>
</span><span class="code-line">
</span><span class="code-line"><span class="k">use</span> <span class="nx">Twilio\Rest\Client</span><span class="p">;</span>
</span><span class="code-line">
</span><span class="code-line"><span class="nv">$account_sid</span> <span class="o">=</span> <span class="s1">&#39;ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&#39;</span><span class="p">;</span>
</span><span class="code-line"><span class="nv">$auth_token</span> <span class="o">=</span> <span class="s1">&#39;your_auth_token&#39;</span><span class="p">;</span>
</span><span class="code-line"><span class="nv">$twilio</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Client</span><span class="p">(</span><span class="nv">$account_sid</span><span class="p">,</span> <span class="nv">$auth_token</span><span class="p">);</span>
</span><span class="code-line">
</span><span class="code-line"><span class="nv">$service</span> <span class="o">=</span> <span class="nv">$twilio</span><span class="o">-&gt;</span><span class="na">messaging</span><span class="o">-&gt;</span><span class="na">v1</span><span class="o">-&gt;</span><span class="na">services</span><span class="o">-&gt;</span><span class="na">create</span><span class="p">(</span><span class="s2">&quot;My First Service&quot;</span><span class="p">,</span>
</span><span class="code-line">                                                    <span class="k">array</span><span class="p">(</span><span class="s1">&#39;statusCallback&#39;</span> <span class="o">=&gt;</span> <span class="s2">&quot;http://requestb.in/1234abcd&quot;</span><span class="p">)</span>
</span><span class="code-line">                                                   <span class="p">);</span>
</span>
                

                    <span class="code-line"><span class="c1"># Get twilio-ruby from twilio.com/docs/libraries/ruby</span>
</span><span class="code-line"><span class="nb">require</span> <span class="s1">&#39;twilio-ruby&#39;</span>
</span><span class="code-line">
</span><span class="code-line"><span class="c1"># Get your Account SID and Auth Token from twilio.com/console</span>
</span><span class="code-line"><span class="n">account_sid</span> <span class="o">=</span> <span class="s1">&#39;ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&#39;</span>
</span><span class="code-line"><span class="n">auth_token</span> <span class="o">=</span> <span class="s1">&#39;your_auth_token&#39;</span>
</span><span class="code-line">
</span><span class="code-line"><span class="c1"># Initialize Twilio Client</span>
</span><span class="code-line"><span class="vi">@client</span> <span class="o">=</span> <span class="no">Twilio</span><span class="o">::</span><span class="no">REST</span><span class="o">::</span><span class="no">Client</span><span class="o">.</span><span class="n">new</span><span class="p">(</span><span class="n">account_sid</span><span class="p">,</span> <span class="n">auth_token</span><span class="p">)</span>
</span><span class="code-line">
</span><span class="code-line"><span class="vi">@service</span> <span class="o">=</span> <span class="vi">@client</span><span class="o">.</span><span class="n">messaging</span><span class="o">.</span><span class="n">v1</span>
</span><span class="code-line">                  <span class="o">.</span><span class="n">services</span>
</span><span class="code-line">                  <span class="o">.</span><span class="n">create</span><span class="p">(</span>
</span><span class="code-line">                    <span class="ss">friendly_name</span><span class="p">:</span> <span class="s1">&#39;My First Service&#39;</span><span class="p">,</span>
</span><span class="code-line">                    <span class="ss">status_callback</span><span class="p">:</span> <span class="s1">&#39;http://requestb.in/1234abcd&#39;</span>
</span><span class="code-line">                  <span class="p">)</span>
</span><span class="code-line">
</span><span class="code-line"><span class="nb">puts</span> <span class="vi">@service</span><span class="o">.</span><span class="n">sid</span>
</span>
                

                    <span class="code-line"><span class="c1"># Download the Python helper library from twilio.com/docs/python/install</span>
</span><span class="code-line"><span class="kn">from</span> <span class="nn">twilio.rest</span> <span class="kn">import</span> <span class="n">Client</span>
</span><span class="code-line">
</span><span class="code-line"><span class="c1"># Your Account Sid and Auth Token from twilio.com/console</span>
</span><span class="code-line"><span class="n">account_sid</span> <span class="o">=</span> <span class="s2">&quot;ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&quot;</span>
</span><span class="code-line"><span class="n">auth_token</span> <span class="o">=</span> <span class="s2">&quot;your_auth_token&quot;</span>
</span><span class="code-line"><span class="n">client</span> <span class="o">=</span> <span class="n">Client</span><span class="p">(</span><span class="n">account_sid</span><span class="p">,</span> <span class="n">auth_token</span><span class="p">)</span>
</span><span class="code-line">
</span><span class="code-line"><span class="n">service</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">messaging</span> \
</span><span class="code-line">                <span class="o">.</span><span class="n">services</span> \
</span><span class="code-line">                <span class="o">.</span><span class="n">create</span><span class="p">(</span><span class="n">friendly_name</span><span class="o">=</span><span class="s2">&quot;My First Service&quot;</span><span class="p">)</span>
</span><span class="code-line">
</span><span class="code-line"><span class="nb">print</span><span class="p">(</span><span class="n">service</span><span class="o">.</span><span class="n">sid</span><span class="p">)</span>
</span>
                

                    <span class="code-line"><span class="kn">import</span> <span class="nn">com.twilio.Twilio</span><span class="p">;</span>
</span><span class="code-line"><span class="kn">import</span> <span class="nn">com.twilio.rest.messaging.v1.Service</span><span class="p">;</span>
</span><span class="code-line">
</span><span class="code-line"><span class="kd">public</span> <span class="kd">class</span> <span class="nc">Example</span> <span class="p">{</span>
</span><span class="code-line">    <span class="c1">// Find your Account Sid and Token at twilio.com/console</span>
</span><span class="code-line">    <span class="kd">public</span> <span class="kd">static</span> <span class="kd">final</span> <span class="n">String</span> <span class="n">ACCOUNT_SID</span> <span class="o">=</span> <span class="s">&quot;ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&quot;</span><span class="p">;</span>
</span><span class="code-line">    <span class="kd">public</span> <span class="kd">static</span> <span class="kd">final</span> <span class="n">String</span> <span class="n">AUTH_TOKEN</span> <span class="o">=</span> <span class="s">&quot;your_auth_token&quot;</span><span class="p">;</span>
</span><span class="code-line">
</span><span class="code-line">    <span class="kd">public</span> <span class="kd">static</span> <span class="kt">void</span> <span class="nf">main</span><span class="p">(</span><span class="n">String</span><span class="o">[]</span> <span class="n">args</span><span class="p">)</span> <span class="p">{</span>
</span><span class="code-line">        <span class="c1">// Initialize the client</span>
</span><span class="code-line">        <span class="n">Twilio</span><span class="p">.</span><span class="na">init</span><span class="p">(</span><span class="n">ACCOUNT_SID</span><span class="p">,</span> <span class="n">AUTH_TOKEN</span><span class="p">);</span>
</span><span class="code-line">
</span><span class="code-line">        <span class="n">Service</span> <span class="n">service</span> <span class="o">=</span> <span class="n">Service</span><span class="p">.</span><span class="na">creator</span><span class="p">(</span><span class="s">&quot;My First Service&quot;</span><span class="p">).</span><span class="na">create</span><span class="p">();</span>
</span><span class="code-line">    <span class="p">}</span>
</span><span class="code-line"><span class="p">}</span>
</span>
                

                    <span class="code-line"><span class="c1"># Download the Python helper library from twilio.com/docs/python/install</span>
</span><span class="code-line"><span class="kn">import</span> <span class="nn">os</span>
</span><span class="code-line"><span class="kn">from</span> <span class="nn">twilio.rest</span> <span class="kn">import</span> <span class="n">Client</span>
</span><span class="code-line">
</span><span class="code-line"><span class="c1"># Your Account Sid and Auth Token from twilio.com/console</span>
</span><span class="code-line"><span class="c1"># To set up environmental variables, see http://twil.io/secure</span>
</span><span class="code-line"><span class="n">account_sid</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s1">&#39;TWILIO_ACCOUNT_SID&#39;</span><span class="p">]</span>
</span><span class="code-line"><span class="n">auth_token</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s1">&#39;TWILIO_AUTH_TOKEN&#39;</span><span class="p">]</span>
</span><span class="code-line"><span class="n">client</span> <span class="o">=</span> <span class="n">Client</span><span class="p">(</span><span class="n">account_sid</span><span class="p">,</span> <span class="n">auth_token</span><span class="p">)</span>
</span><span class="code-line">
</span><span class="code-line"><span class="n">service</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">messaging</span> \
</span><span class="code-line">                <span class="o">.</span><span class="n">services</span> \
</span><span class="code-line">                <span class="o">.</span><span class="n">create</span><span class="p">(</span><span class="n">friendly_name</span><span class="o">=</span><span class="s2">&quot;My First Service&quot;</span><span class="p">)</span>
</span><span class="code-line">
</span><span class="code-line"><span class="nb">print</span><span class="p">(</span><span class="n">service</span><span class="o">.</span><span class="n">sid</span><span class="p">)</span>
</span>
                

                    <span class="code-line"><span class="kn">import</span> <span class="nn">com.twilio.Twilio</span><span class="p">;</span>
</span><span class="code-line"><span class="kn">import</span> <span class="nn">com.twilio.rest.messaging.v1.Service</span><span class="p">;</span>
</span><span class="code-line">
</span><span class="code-line"><span class="kd">public</span> <span class="kd">class</span> <span class="nc">Example</span> <span class="p">{</span>
</span><span class="code-line">    <span class="c1">// Get your Account SID and Auth Token from https://twilio.com/console</span>
</span><span class="code-line">    <span class="c1">// To set up environment variables, see http://twil.io/secure</span>
</span><span class="code-line">    <span class="kd">public</span> <span class="kd">static</span> <span class="kd">final</span> <span class="n">String</span> <span class="n">ACCOUNT_SID</span> <span class="o">=</span> <span class="n">System</span><span class="p">.</span><span class="na">getenv</span><span class="p">(</span><span class="s">&quot;TWILIO_ACCOUNT_SID&quot;</span><span class="p">);</span>
</span><span class="code-line">    <span class="kd">public</span> <span class="kd">static</span> <span class="kd">final</span> <span class="n">String</span> <span class="n">AUTH_TOKEN</span> <span class="o">=</span> <span class="n">System</span><span class="p">.</span><span class="na">getenv</span><span class="p">(</span><span class="s">&quot;TWILIO_AUTH_TOKEN&quot;</span><span class="p">);</span>
</span><span class="code-line">
</span><span class="code-line">    <span class="kd">public</span> <span class="kd">static</span> <span class="kt">void</span> <span class="nf">main</span><span class="p">(</span><span class="n">String</span><span class="o">[]</span> <span class="n">args</span><span class="p">)</span> <span class="p">{</span>
</span><span class="code-line">        <span class="c1">// Initialize the client</span>
</span><span class="code-line">        <span class="n">Twilio</span><span class="p">.</span><span class="na">init</span><span class="p">(</span><span class="n">ACCOUNT_SID</span><span class="p">,</span> <span class="n">AUTH_TOKEN</span><span class="p">);</span>
</span><span class="code-line">
</span><span class="code-line">        <span class="n">Service</span> <span class="n">service</span> <span class="o">=</span> <span class="n">Service</span><span class="p">.</span><span class="na">creator</span><span class="p">(</span><span class="s">&quot;My First Service&quot;</span><span class="p">).</span><span class="na">create</span><span class="p">();</span>
</span><span class="code-line">    <span class="p">}</span>
</span><span class="code-line"><span class="p">}</span>
</span>
                

                    <span class="code-line">curl <span class="s1">&#39;https://messaging.twilio.com/v1/Services&#39;</span> -X POST <span class="se">\</span>
</span><span class="code-line">    --data-urlencode <span class="s1">&#39;FriendlyName=My First Service&#39;</span> <span class="se">\</span>
</span><span class="code-line">    --data-urlencode <span class="s1">&#39;StatusCallback=http://requestb.in/1234abcd&#39;</span> <span class="se">\</span>
</span><span class="code-line">    -u ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token
</span>
                

グローバルな配信をローカルに最適化

  • A2P 10DLC:ローカル番号にてメッセージを大規模に配信。検証済みの米国A2P 10桁ロングコード(10DL)を登録。
  • 地域ごとのメッセージ送信:国、地域、フリーダイヤルなど、65,000のプリフィックスから選択可能
  • Sticky Sender:同一の送信者IDや電話番号からメッセージを送信することにより、顧客サポートの一貫性を確保
  • 地域コードと国のGeomatch:ユーザーの地域コード(米国のみ)や国から電話番号を自動選択
  • Node.js
  • C#
  • PHP
  • Ruby
  • Python
  • Java
  • curl

                    <span class="code-line"><span class="c1">// Download the helper library from https://www.twilio.com/docs/node/install</span>
</span><span class="code-line"><span class="c1">// Your Account Sid and Auth Token from twilio.com/console</span>
</span><span class="code-line"><span class="c1">// DANGER! This is insecure. See http://twil.io/secure</span>
</span><span class="code-line"><span class="kd">const</span> <span class="nx">accountSid</span> <span class="o">=</span> <span class="s1">&#39;ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&#39;</span><span class="p">;</span>
</span><span class="code-line"><span class="kd">const</span> <span class="nx">authToken</span> <span class="o">=</span> <span class="s1">&#39;your_auth_token&#39;</span><span class="p">;</span>
</span><span class="code-line"><span class="kd">const</span> <span class="nx">client</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;twilio&#39;</span><span class="p">)(</span><span class="nx">accountSid</span><span class="p">,</span> <span class="nx">authToken</span><span class="p">);</span>
</span><span class="code-line">
</span><span class="code-line"><span class="nx">client</span><span class="p">.</span><span class="nx">messages</span><span class="p">(</span><span class="s1">&#39;MMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&#39;</span><span class="p">)</span>
</span><span class="code-line">      <span class="p">.</span><span class="nx">media</span><span class="p">(</span><span class="s1">&#39;MEXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&#39;</span><span class="p">)</span>
</span><span class="code-line">      <span class="p">.</span><span class="nx">fetch</span><span class="p">()</span>
</span><span class="code-line">      <span class="p">.</span><span class="nx">then</span><span class="p">(</span><span class="nx">media</span> <span class="p">=&gt;</span> <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">media</span><span class="p">.</span><span class="nx">contentType</span><span class="p">));</span>
</span>
                

                    <span class="code-line"><span class="c1">// Install the C# / .NET helper library from twilio.com/docs/csharp/install</span>
</span><span class="code-line">
</span><span class="code-line"><span class="k">using</span> <span class="nn">System</span><span class="p">;</span>
</span><span class="code-line"><span class="k">using</span> <span class="nn">Twilio</span><span class="p">;</span>
</span><span class="code-line"><span class="k">using</span> <span class="nn">Twilio.Rest.Api.V2010.Account.Message</span><span class="p">;</span>
</span><span class="code-line">
</span><span class="code-line">
</span><span class="code-line"><span class="k">class</span> <span class="nc">Program</span> 
</span><span class="code-line"><span class="p">{</span>
</span><span class="code-line">    <span class="k">static</span> <span class="k">void</span> <span class="nf">Main</span><span class="p">(</span><span class="kt">string</span><span class="p">[]</span> <span class="n">args</span><span class="p">)</span>
</span><span class="code-line">    <span class="p">{</span>
</span><span class="code-line">        <span class="c1">// Find your Account Sid and Token at twilio.com/console</span>
</span><span class="code-line">        <span class="c1">// DANGER! This is insecure. See http://twil.io/secure</span>
</span><span class="code-line">        <span class="k">const</span> <span class="kt">string</span> <span class="n">accountSid</span> <span class="p">=</span> <span class="s">&quot;ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&quot;</span><span class="p">;</span>
</span><span class="code-line">        <span class="k">const</span> <span class="kt">string</span> <span class="n">authToken</span> <span class="p">=</span> <span class="s">&quot;your_auth_token&quot;</span><span class="p">;</span>
</span><span class="code-line">
</span><span class="code-line">        <span class="n">TwilioClient</span><span class="p">.</span><span class="n">Init</span><span class="p">(</span><span class="n">accountSid</span><span class="p">,</span> <span class="n">authToken</span><span class="p">);</span>
</span><span class="code-line">
</span><span class="code-line">        <span class="kt">var</span> <span class="n">media</span> <span class="p">=</span> <span class="n">MediaResource</span><span class="p">.</span><span class="n">Fetch</span><span class="p">(</span>
</span><span class="code-line">            <span class="n">pathMessageSid</span><span class="p">:</span> <span class="s">&quot;MMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&quot;</span><span class="p">,</span>
</span><span class="code-line">            <span class="n">pathSid</span><span class="p">:</span> <span class="s">&quot;MEXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&quot;</span>
</span><span class="code-line">        <span class="p">);</span>
</span><span class="code-line">
</span><span class="code-line">        <span class="n">Console</span><span class="p">.</span><span class="n">WriteLine</span><span class="p">(</span><span class="n">media</span><span class="p">.</span><span class="n">ContentType</span><span class="p">);</span>
</span><span class="code-line">    <span class="p">}</span>
</span><span class="code-line"><span class="p">}</span>
</span>
                

                    <span class="code-line"><span class="cp">&lt;?php</span>
</span><span class="code-line">
</span><span class="code-line"><span class="c1">// Update the path below to your autoload.php,</span>
</span><span class="code-line"><span class="c1">// see https://getcomposer.org/doc/01-basic-usage.md</span>
</span><span class="code-line"><span class="k">require_once</span> <span class="s1">&#39;/path/to/vendor/autoload.php&#39;</span><span class="p">;</span>
</span><span class="code-line">
</span><span class="code-line"><span class="k">use</span> <span class="nx">Twilio\Rest\Client</span><span class="p">;</span>
</span><span class="code-line">
</span><span class="code-line"><span class="c1">// Find your Account Sid and Auth Token at twilio.com/console</span>
</span><span class="code-line"><span class="c1">// DANGER! This is insecure. See http://twil.io/secure</span>
</span><span class="code-line"><span class="nv">$sid</span>    <span class="o">=</span> <span class="s2">&quot;ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&quot;</span><span class="p">;</span>
</span><span class="code-line"><span class="nv">$token</span>  <span class="o">=</span> <span class="s2">&quot;your_auth_token&quot;</span><span class="p">;</span>
</span><span class="code-line"><span class="nv">$twilio</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Client</span><span class="p">(</span><span class="nv">$sid</span><span class="p">,</span> <span class="nv">$token</span><span class="p">);</span>
</span><span class="code-line">
</span><span class="code-line"><span class="nv">$media</span> <span class="o">=</span> <span class="nv">$twilio</span><span class="o">-&gt;</span><span class="na">messages</span><span class="p">(</span><span class="s2">&quot;MMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&quot;</span><span class="p">)</span>
</span><span class="code-line">                <span class="o">-&gt;</span><span class="na">media</span><span class="p">(</span><span class="s2">&quot;MEXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&quot;</span><span class="p">)</span>
</span><span class="code-line">                <span class="o">-&gt;</span><span class="na">fetch</span><span class="p">();</span>
</span><span class="code-line">
</span><span class="code-line"><span class="k">print</span><span class="p">(</span><span class="nv">$media</span><span class="o">-&gt;</span><span class="na">contentType</span><span class="p">);</span>
</span>
                

                    <span class="code-line"><span class="c1"># Download the helper library from https://www.twilio.com/docs/ruby/install</span>
</span><span class="code-line"><span class="nb">require</span> <span class="s1">&#39;rubygems&#39;</span>
</span><span class="code-line"><span class="nb">require</span> <span class="s1">&#39;twilio-ruby&#39;</span>
</span><span class="code-line">
</span><span class="code-line"><span class="c1"># Your Account Sid and Auth Token from twilio.com/console</span>
</span><span class="code-line"><span class="c1"># DANGER! This is insecure. See http://twil.io/secure</span>
</span><span class="code-line"><span class="n">account_sid</span> <span class="o">=</span> <span class="s1">&#39;ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&#39;</span>
</span><span class="code-line"><span class="n">auth_token</span> <span class="o">=</span> <span class="s1">&#39;your_auth_token&#39;</span>
</span><span class="code-line"><span class="vi">@client</span> <span class="o">=</span> <span class="no">Twilio</span><span class="o">::</span><span class="no">REST</span><span class="o">::</span><span class="no">Client</span><span class="o">.</span><span class="n">new</span><span class="p">(</span><span class="n">account_sid</span><span class="p">,</span> <span class="n">auth_token</span><span class="p">)</span>
</span><span class="code-line">
</span><span class="code-line"><span class="n">media</span> <span class="o">=</span> <span class="vi">@client</span><span class="o">.</span><span class="n">messages</span><span class="p">(</span><span class="s1">&#39;MMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&#39;</span><span class="p">)</span>
</span><span class="code-line">               <span class="o">.</span><span class="n">media</span><span class="p">(</span><span class="s1">&#39;MEXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&#39;</span><span class="p">)</span>
</span><span class="code-line">               <span class="o">.</span><span class="n">fetch</span>
</span><span class="code-line">
</span><span class="code-line"><span class="nb">puts</span> <span class="n">media</span><span class="o">.</span><span class="n">content_type</span>
</span>
                

                    <span class="code-line"><span class="c1"># Download the helper library from https://www.twilio.com/docs/python/install</span>
</span><span class="code-line"><span class="kn">from</span> <span class="nn">twilio.rest</span> <span class="kn">import</span> <span class="n">Client</span>
</span><span class="code-line">
</span><span class="code-line">
</span><span class="code-line"><span class="c1"># Your Account Sid and Auth Token from twilio.com/console</span>
</span><span class="code-line"><span class="c1"># DANGER! This is insecure. See http://twil.io/secure</span>
</span><span class="code-line"><span class="n">account_sid</span> <span class="o">=</span> <span class="s1">&#39;ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&#39;</span>
</span><span class="code-line"><span class="n">auth_token</span> <span class="o">=</span> <span class="s1">&#39;your_auth_token&#39;</span>
</span><span class="code-line"><span class="n">client</span> <span class="o">=</span> <span class="n">Client</span><span class="p">(</span><span class="n">account_sid</span><span class="p">,</span> <span class="n">auth_token</span><span class="p">)</span>
</span><span class="code-line">
</span><span class="code-line"><span class="n">media</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">messages</span><span class="p">(</span><span class="s1">&#39;MMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&#39;</span><span class="p">)</span> \
</span><span class="code-line">              <span class="o">.</span><span class="n">media</span><span class="p">(</span><span class="s1">&#39;MEXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&#39;</span><span class="p">)</span> \
</span><span class="code-line">              <span class="o">.</span><span class="n">fetch</span><span class="p">()</span>
</span><span class="code-line">
</span><span class="code-line"><span class="nb">print</span><span class="p">(</span><span class="n">media</span><span class="o">.</span><span class="n">content_type</span><span class="p">)</span>
</span>
                

                    <span class="code-line"><span class="c1">// Install the Java helper library from twilio.com/docs/java/install</span>
</span><span class="code-line">
</span><span class="code-line"><span class="kn">import</span> <span class="nn">com.twilio.Twilio</span><span class="p">;</span>
</span><span class="code-line"><span class="kn">import</span> <span class="nn">com.twilio.rest.api.v2010.account.message.Media</span><span class="p">;</span>
</span><span class="code-line">
</span><span class="code-line"><span class="kd">public</span> <span class="kd">class</span> <span class="nc">Example</span> <span class="p">{</span>
</span><span class="code-line">    <span class="c1">// Find your Account Sid and Token at twilio.com/console</span>
</span><span class="code-line">    <span class="c1">// DANGER! This is insecure. See http://twil.io/secure</span>
</span><span class="code-line">    <span class="kd">public</span> <span class="kd">static</span> <span class="kd">final</span> <span class="n">String</span> <span class="n">ACCOUNT_SID</span> <span class="o">=</span> <span class="s">&quot;ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&quot;</span><span class="p">;</span>
</span><span class="code-line">    <span class="kd">public</span> <span class="kd">static</span> <span class="kd">final</span> <span class="n">String</span> <span class="n">AUTH_TOKEN</span> <span class="o">=</span> <span class="s">&quot;your_auth_token&quot;</span><span class="p">;</span>
</span><span class="code-line">
</span><span class="code-line">    <span class="kd">public</span> <span class="kd">static</span> <span class="kt">void</span> <span class="nf">main</span><span class="p">(</span><span class="n">String</span><span class="o">[]</span> <span class="n">args</span><span class="p">)</span> <span class="p">{</span>
</span><span class="code-line">        <span class="n">Twilio</span><span class="p">.</span><span class="na">init</span><span class="p">(</span><span class="n">ACCOUNT_SID</span><span class="p">,</span> <span class="n">AUTH_TOKEN</span><span class="p">);</span>
</span><span class="code-line">        <span class="n">Media</span> <span class="n">media</span> <span class="o">=</span> <span class="n">Media</span><span class="p">.</span><span class="na">fetcher</span><span class="p">(</span>
</span><span class="code-line">                <span class="s">&quot;MMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&quot;</span><span class="p">,</span>
</span><span class="code-line">                <span class="s">&quot;MEXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&quot;</span><span class="p">)</span>
</span><span class="code-line">            <span class="p">.</span><span class="na">fetch</span><span class="p">();</span>
</span><span class="code-line">
</span><span class="code-line">        <span class="n">System</span><span class="p">.</span><span class="na">out</span><span class="p">.</span><span class="na">println</span><span class="p">(</span><span class="n">media</span><span class="p">.</span><span class="na">getContentType</span><span class="p">());</span>
</span><span class="code-line">    <span class="p">}</span>
</span><span class="code-line"><span class="p">}</span>
</span>
                

                    <span class="code-line">curl -X GET <span class="s1">&#39;https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages/MMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Media/MEXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.json&#39;</span> <span class="se">\</span>
</span><span class="code-line">-u ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token
</span>
                

メッセージコンテンツを正確に伝達

  • コンテンツAPI:複数チャネル間でリッチメッセージコンテンツを変換
  • インテリジェントに文字連結:長いメッセージを自動的に分割後、キャリア用のヘッダーを付与しメッセージを再連結
  • スマートエンコーディング:SMSメッセージをエンコーディングし、最小サイズで送信(GSM-7以外の文字はUCS-2に変換)
  • Node.js
  • C#
  • PHP
  • Ruby
  • Python
  • Java
  • curl
  • twilio-cli
//Downloadthehelperlibraryfromhttps://www.twilio.com/docs/node/install//FindyourAccountSIDandAuthTokenattwilio.com/console//andsettheenvironmentvariables.Seehttp://twil.io/secureconstaccountSid=process.env.TWILIO_ACCOUNT_SID;constauthToken=process.env.TWILIO_AUTH_TOKEN;constclient=require('twilio')(accountSid,authToken);client.messages.create({from:'+15017122661',body:'body',to:'+15558675310'}).then(message=>console.log(message.sid));
// Install the C# / .NET helper library from twilio.com/docs/csharp/installusingSystem;usingTwilio;usingTwilio.Rest.Api.V2010.Account;classProgram{staticvoidMain(string[]args){// Find your Account SID and Auth Token at twilio.com/console// and set the environment variables. See http://twil.io/securestringaccountSid=Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID");stringauthToken=Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN");TwilioClient.Init(accountSid,authToken);varmessage=MessageResource.Create(from:newTwilio.Types.PhoneNumber("+15017122661"),body:"body",to:newTwilio.Types.PhoneNumber("+15558675310"));Console.WriteLine(message.Sid);}}
<?php// Update the path below to your autoload.php,// see https://getcomposer.org/doc/01-basic-usage.mdrequire_once'/path/to/vendor/autoload.php';useTwilio\Rest\Client;// Find your Account SID and Auth Token at twilio.com/console// and set the environment variables. See http://twil.io/secure$sid=getenv("TWILIO_ACCOUNT_SID");$token=getenv("TWILIO_AUTH_TOKEN");$twilio=newClient($sid,$token);$message=$twilio->messages->create("+15558675310",// to["from"=>"+15017122661","body"=>"body"]);print($message->sid);
# Download the helper library from https://www.twilio.com/docs/ruby/installrequire'rubygems'require'twilio-ruby'# Find your Account SID and Auth Token at twilio.com/console# and set the environment variables. See http://twil.io/secureaccount_sid=ENV['TWILIO_ACCOUNT_SID']auth_token=ENV['TWILIO_AUTH_TOKEN']@client=Twilio::REST::Client.new(account_sid,auth_token)message=@client.messages.create(from:'+15017122661',body:'body',to:'+15558675310')putsmessage.sid
# Download the helper library from https://www.twilio.com/docs/python/installimportosfromtwilio.restimportClient# Find your Account SID and Auth Token at twilio.com/console# and set the environment variables. See http://twil.io/secureaccount_sid=os.environ['TWILIO_ACCOUNT_SID']auth_token=os.environ['TWILIO_AUTH_TOKEN']client=Client(account_sid,auth_token)message=client.messages.create(from_='+15017122661',body='body',to='+15558675310')print(message.sid)
// Install the Java helper library from twilio.com/docs/java/installimportcom.twilio.Twilio;importcom.twilio.rest.api.v2010.account.Message;importcom.twilio.type.PhoneNumber;publicclassExample{// Find your Account SID and Auth Token at twilio.com/console// and set the environment variables. See http://twil.io/securepublicstaticfinalStringACCOUNT_SID=System.getenv("TWILIO_ACCOUNT_SID");publicstaticfinalStringAUTH_TOKEN=System.getenv("TWILIO_AUTH_TOKEN");publicstaticvoidmain(String[]args){Twilio.init(ACCOUNT_SID,AUTH_TOKEN);Messagemessage=Message.creator(newcom.twilio.type.PhoneNumber("+15558675310"),newcom.twilio.type.PhoneNumber("+15017122661"),"body").create();System.out.println(message.getSid());}}
curl -X POST https://api.twilio.com/2010-04-01/Accounts/$TWILIO_ACCOUNT_SID/Messages.json \--data-urlencode "From=+15017122661"\--data-urlencode "Body=body"\--data-urlencode "To=+15558675310"\-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN
#Installthetwilio-clifromhttps://twil.io/clitwilioapi:core:messages:create\--from +15017122661 \--body body \--to +15558675310

メッセージの送信待機・受信設定をプログラム可能

  • SMSの配信有効時間設定:メッセージの送信待機後、送信エラーになるまでの時間を設定可能
  • Inbound webhooks:特定URLにHTTP POSTリクエスト、またはHTTP GETリクエストを送信しメッセージを受信
  • Conversations API:Conversations APIを使用し、メッセージの受信設定を変更。Conversation Resourceを作成し、スレッドをアーカイブすることが可能
  • Node.js
  • Node.js
  • C#
  • PHP
  • Ruby
  • C#
  • PHP
  • Python
  • Ruby
  • Java
  • Python
  • Java
  • Python
  • Java
  • curl

                    <span class="code-line"><span class="c1">// Twilio Credentials</span>
</span><span class="code-line"><span class="kd">const</span> <span class="nx">accountSid</span> <span class="o">=</span> <span class="s1">&#39;ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&#39;</span><span class="p">;</span>
</span><span class="code-line"><span class="kd">const</span> <span class="nx">authToken</span> <span class="o">=</span> <span class="s1">&#39;your_auth_token&#39;</span><span class="p">;</span>
</span><span class="code-line">
</span><span class="code-line"><span class="c1">// require the Twilio module and create a REST client</span>
</span><span class="code-line"><span class="kd">const</span> <span class="nx">client</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;twilio&#39;</span><span class="p">)(</span><span class="nx">accountSid</span><span class="p">,</span> <span class="nx">authToken</span><span class="p">);</span>
</span><span class="code-line">
</span><span class="code-line"><span class="nx">client</span><span class="p">.</span><span class="nx">messages</span><span class="p">.</span><span class="nx">create</span><span class="p">(</span>
</span><span class="code-line">  <span class="p">{</span>
</span><span class="code-line">    <span class="nx">to</span><span class="o">:</span> <span class="s1">&#39;+15558675310&#39;</span><span class="p">,</span>
</span><span class="code-line">    <span class="nx">from</span><span class="o">:</span> <span class="s1">&#39;+15017122661&#39;</span><span class="p">,</span>
</span><span class="code-line">    <span class="nx">body</span><span class="o">:</span> <span class="s1">&#39;McAvoy or Stewart? These timelines can get so confusing.&#39;</span><span class="p">,</span>
</span><span class="code-line">    <span class="nx">statusCallback</span><span class="o">:</span> <span class="s1">&#39;http://requestb.in/1234abcd&#39;</span><span class="p">,</span>
</span><span class="code-line">  <span class="p">},</span>
</span><span class="code-line">  <span class="p">(</span><span class="nx">err</span><span class="p">,</span> <span class="nx">message</span><span class="p">)</span> <span class="p">=&gt;</span> <span class="p">{</span>
</span><span class="code-line">    <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">message</span><span class="p">.</span><span class="nx">sid</span><span class="p">);</span>
</span><span class="code-line">  <span class="p">}</span>
</span><span class="code-line"><span class="p">);</span>
</span>
                

                    <span class="code-line"><span class="c1">// Twilio Credentials</span>
</span><span class="code-line"><span class="kd">const</span> <span class="nx">accountSid</span> <span class="o">=</span> <span class="s1">&#39;ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&#39;</span><span class="p">;</span>
</span><span class="code-line"><span class="kd">const</span> <span class="nx">authToken</span> <span class="o">=</span> <span class="s1">&#39;your_auth_token&#39;</span><span class="p">;</span>
</span><span class="code-line">
</span><span class="code-line"><span class="c1">// require the Twilio module and create a REST client</span>
</span><span class="code-line"><span class="kd">const</span> <span class="nx">client</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;twilio&#39;</span><span class="p">)(</span><span class="nx">accountSid</span><span class="p">,</span> <span class="nx">authToken</span><span class="p">);</span>
</span><span class="code-line">
</span><span class="code-line"><span class="nx">client</span><span class="p">.</span><span class="nx">messages</span>
</span><span class="code-line">  <span class="p">.</span><span class="nx">create</span><span class="p">({</span>
</span><span class="code-line">    <span class="nx">to</span><span class="o">:</span> <span class="s1">&#39;+15558675310&#39;</span><span class="p">,</span>
</span><span class="code-line">    <span class="nx">from</span><span class="o">:</span> <span class="s1">&#39;+15017122661&#39;</span><span class="p">,</span>
</span><span class="code-line">    <span class="nx">body</span><span class="o">:</span> <span class="s1">&#39;McAvoy or Stewart? These timelines can get so confusing.&#39;</span><span class="p">,</span>
</span><span class="code-line">    <span class="nx">statusCallback</span><span class="o">:</span> <span class="s1">&#39;http://requestb.in/1234abcd&#39;</span><span class="p">,</span>
</span><span class="code-line">  <span class="p">})</span>
</span><span class="code-line">  <span class="p">.</span><span class="nx">then</span><span class="p">(</span><span class="nx">message</span> <span class="p">=&gt;</span> <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">message</span><span class="p">.</span><span class="nx">sid</span><span class="p">));</span>
</span>
                

                    <span class="code-line"><span class="c1">// Download the twilio-csharp library from twilio.com/docs/csharp/install</span>
</span><span class="code-line"><span class="k">using</span> <span class="nn">System</span><span class="p">;</span>
</span><span class="code-line"><span class="k">using</span> <span class="nn">Twilio</span><span class="p">;</span>
</span><span class="code-line"><span class="k">class</span> <span class="nc">Example</span>
</span><span class="code-line"><span class="p">{</span>
</span><span class="code-line"> <span class="k">static</span> <span class="k">void</span> <span class="nf">Main</span><span class="p">(</span><span class="kt">string</span><span class="p">[]</span> <span class="n">args</span><span class="p">)</span>
</span><span class="code-line"> <span class="p">{</span>
</span><span class="code-line">    <span class="c1">// Find your Account Sid and Auth Token at twilio.com/user/account</span>
</span><span class="code-line">    <span class="kt">string</span> <span class="n">AccountSid</span> <span class="p">=</span> <span class="s">&quot;ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&quot;</span><span class="p">;</span>
</span><span class="code-line">    <span class="kt">string</span> <span class="n">AuthToken</span> <span class="p">=</span> <span class="s">&quot;your_auth_token&quot;</span><span class="p">;</span>
</span><span class="code-line">    <span class="kt">var</span> <span class="n">twilio</span> <span class="p">=</span> <span class="k">new</span> <span class="n">TwilioRestClient</span><span class="p">(</span><span class="n">AccountSid</span><span class="p">,</span> <span class="n">AuthToken</span><span class="p">);</span>
</span><span class="code-line">
</span><span class="code-line">    <span class="kt">var</span> <span class="n">message</span> <span class="p">=</span> <span class="n">twilio</span><span class="p">.</span><span class="n">SendMessage</span><span class="p">(</span>
</span><span class="code-line">        <span class="s">&quot;+15017122661&quot;</span><span class="p">,</span> <span class="s">&quot;+15558675310&quot;</span><span class="p">,</span>
</span><span class="code-line">        <span class="s">&quot;McAvoy or Stewart? These timelines can get so confusing.&quot;</span><span class="p">,</span>
</span><span class="code-line">        <span class="s">&quot;http://requestb.in/1234abcd&quot;</span>
</span><span class="code-line">    <span class="p">);</span>
</span><span class="code-line">    <span class="n">Console</span><span class="p">.</span><span class="n">WriteLine</span><span class="p">(</span><span class="n">message</span><span class="p">.</span><span class="n">Sid</span><span class="p">);</span>
</span><span class="code-line"> <span class="p">}</span>
</span><span class="code-line"><span class="p">}</span>
</span>
                

                    <span class="code-line"><span class="cp">&lt;?php</span>
</span><span class="code-line">
</span><span class="code-line"><span class="c1">// this line loads the library </span>
</span><span class="code-line"><span class="k">require</span><span class="p">(</span><span class="s1">&#39;/path/to/twilio-php/Services/Twilio.php&#39;</span><span class="p">);</span> 
</span><span class="code-line"> 
</span><span class="code-line"><span class="nv">$account_sid</span> <span class="o">=</span> <span class="s1">&#39;ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&#39;</span><span class="p">;</span> 
</span><span class="code-line"><span class="nv">$auth_token</span> <span class="o">=</span> <span class="s1">&#39;your_auth_token&#39;</span><span class="p">;</span> 
</span><span class="code-line"><span class="nv">$client</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Services_Twilio</span><span class="p">(</span><span class="nv">$account_sid</span><span class="p">,</span> <span class="nv">$auth_token</span><span class="p">);</span> 
</span><span class="code-line"> 
</span><span class="code-line"><span class="nv">$client</span><span class="o">-&gt;</span><span class="na">account</span><span class="o">-&gt;</span><span class="na">messages</span><span class="o">-&gt;</span><span class="na">create</span><span class="p">(</span><span class="k">array</span><span class="p">(</span> 
</span><span class="code-line">    <span class="s1">&#39;To&#39;</span> <span class="o">=&gt;</span> <span class="s2">&quot;+15558675310&quot;</span><span class="p">,</span> 
</span><span class="code-line">    <span class="s1">&#39;From&#39;</span> <span class="o">=&gt;</span> <span class="s2">&quot;+15017122661&quot;</span><span class="p">,</span> 
</span><span class="code-line">    <span class="s1">&#39;Body&#39;</span> <span class="o">=&gt;</span> <span class="s2">&quot;McAvoy or Stewart? These timelines can get so confusing.&quot;</span><span class="p">,</span>
</span><span class="code-line">    <span class="s1">&#39;StatusCallback&#39;</span> <span class="o">=&gt;</span> <span class="s2">&quot;http://requestb.in/1234abcd&quot;</span>
</span><span class="code-line"><span class="p">));</span>
</span>
                

                    <span class="code-line"><span class="nb">require</span> <span class="s1">&#39;rubygems&#39;</span> <span class="c1"># not necessary with ruby 1.9 but included for completeness</span>
</span><span class="code-line"><span class="nb">require</span> <span class="s1">&#39;twilio-ruby&#39;</span>
</span><span class="code-line">
</span><span class="code-line"><span class="c1"># put your own credentials here</span>
</span><span class="code-line"><span class="n">account_sid</span> <span class="o">=</span> <span class="s1">&#39;ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&#39;</span>
</span><span class="code-line"><span class="n">auth_token</span> <span class="o">=</span> <span class="s1">&#39;your_auth_token&#39;</span>
</span><span class="code-line">
</span><span class="code-line"><span class="c1"># set up a client to talk to the Twilio REST API</span>
</span><span class="code-line"><span class="n">client</span> <span class="o">=</span> <span class="no">Twilio</span><span class="o">::</span><span class="no">REST</span><span class="o">::</span><span class="no">Client</span><span class="o">.</span><span class="n">new</span> <span class="n">account_sid</span><span class="p">,</span> <span class="n">auth_token</span>
</span><span class="code-line">
</span><span class="code-line"><span class="n">body</span> <span class="o">=</span> <span class="s1">&#39;McAvoy or Stewart? These timelines can get so confusing.&#39;</span>
</span><span class="code-line"><span class="n">client</span><span class="o">.</span><span class="n">account</span><span class="o">.</span><span class="n">messages</span><span class="o">.</span><span class="n">create</span><span class="p">(</span><span class="ss">from</span><span class="p">:</span> <span class="s1">&#39;+15017122661&#39;</span><span class="p">,</span>
</span><span class="code-line">                               <span class="ss">to</span><span class="p">:</span> <span class="s1">&#39;+15558675310&#39;</span><span class="p">,</span>
</span><span class="code-line">                               <span class="ss">body</span><span class="p">:</span> <span class="n">body</span><span class="p">,</span>
</span><span class="code-line">                               <span class="ss">status_callback</span><span class="p">:</span> <span class="s1">&#39;http://requestb.in/1234abcd&#39;</span><span class="p">)</span>
</span>
                

                    <span class="code-line"><span class="c1">// Download the twilio-csharp library from twilio.com/docs/libraries/csharp</span>
</span><span class="code-line"><span class="k">using</span> <span class="nn">System</span><span class="p">;</span>
</span><span class="code-line"><span class="k">using</span> <span class="nn">Twilio</span><span class="p">;</span>
</span><span class="code-line"><span class="k">using</span> <span class="nn">Twilio.Rest.Api.V2010.Account</span><span class="p">;</span>
</span><span class="code-line"><span class="k">using</span> <span class="nn">Twilio.Types</span><span class="p">;</span>
</span><span class="code-line">
</span><span class="code-line"><span class="k">class</span> <span class="nc">Example</span>
</span><span class="code-line"><span class="p">{</span>
</span><span class="code-line">   <span class="k">static</span> <span class="k">void</span> <span class="nf">Main</span><span class="p">(</span><span class="kt">string</span><span class="p">[]</span> <span class="n">args</span><span class="p">)</span>
</span><span class="code-line">   <span class="p">{</span>
</span><span class="code-line">        <span class="c1">// Find your Account Sid and Auth Token at twilio.com/console</span>
</span><span class="code-line">        <span class="k">const</span> <span class="kt">string</span> <span class="n">accountSid</span> <span class="p">=</span> <span class="s">&quot;ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&quot;</span><span class="p">;</span>
</span><span class="code-line">        <span class="k">const</span> <span class="kt">string</span> <span class="n">authToken</span> <span class="p">=</span> <span class="s">&quot;your_auth_token&quot;</span><span class="p">;</span>
</span><span class="code-line">        <span class="n">TwilioClient</span><span class="p">.</span><span class="n">Init</span><span class="p">(</span><span class="n">accountSid</span><span class="p">,</span> <span class="n">authToken</span><span class="p">);</span>
</span><span class="code-line">
</span><span class="code-line">        <span class="kt">var</span> <span class="n">to</span> <span class="p">=</span> <span class="k">new</span> <span class="n">PhoneNumber</span><span class="p">(</span><span class="s">&quot;+15017122661&quot;</span><span class="p">);</span>
</span><span class="code-line">        <span class="kt">var</span> <span class="n">message</span> <span class="p">=</span> <span class="n">MessageResource</span><span class="p">.</span><span class="n">Create</span><span class="p">(</span>
</span><span class="code-line">            <span class="n">to</span><span class="p">,</span>
</span><span class="code-line">            <span class="k">from</span><span class="p">:</span> <span class="k">new</span> <span class="n">PhoneNumber</span><span class="p">(</span><span class="s">&quot;+15558675310&quot;</span><span class="p">),</span>
</span><span class="code-line">            <span class="n">body</span><span class="p">:</span> <span class="s">&quot;McAvoy or Stewart? These timelines can get so confusing.&quot;</span><span class="p">,</span>
</span><span class="code-line">            <span class="n">statusCallback</span><span class="p">:</span> <span class="k">new</span> <span class="n">Uri</span><span class="p">(</span><span class="s">&quot;http://requestb.in/1234abcd&quot;</span><span class="p">));</span>
</span><span class="code-line">
</span><span class="code-line">        <span class="n">Console</span><span class="p">.</span><span class="n">WriteLine</span><span class="p">(</span><span class="n">message</span><span class="p">.</span><span class="n">Sid</span><span class="p">);</span>
</span><span class="code-line">   <span class="p">}</span>
</span><span class="code-line"><span class="p">}</span>
</span>
                

                    <span class="code-line"><span class="cp">&lt;?php</span>
</span><span class="code-line"><span class="c1">// Get the PHP helper library from https://twilio.com/docs/libraries/php</span>
</span><span class="code-line"><span class="k">require_once</span> <span class="s1">&#39;/path/to/vendor/autoload.php&#39;</span><span class="p">;</span> <span class="c1">// Loads the library</span>
</span><span class="code-line"><span class="k">use</span> <span class="nx">Twilio\Rest\Client</span><span class="p">;</span>
</span><span class="code-line">
</span><span class="code-line"><span class="c1">// Your Account Sid and Auth Token from twilio.com/user/account</span>
</span><span class="code-line"><span class="nv">$sid</span> <span class="o">=</span> <span class="s2">&quot;ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&quot;</span><span class="p">;</span>
</span><span class="code-line"><span class="nv">$token</span> <span class="o">=</span> <span class="s2">&quot;your_auth_token&quot;</span><span class="p">;</span>
</span><span class="code-line"><span class="nv">$client</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Client</span><span class="p">(</span><span class="nv">$sid</span><span class="p">,</span> <span class="nv">$token</span><span class="p">);</span>
</span><span class="code-line">
</span><span class="code-line"><span class="nv">$client</span><span class="o">-&gt;</span><span class="na">messages</span><span class="o">-&gt;</span><span class="na">create</span><span class="p">(</span>
</span><span class="code-line">    <span class="s1">&#39;+15558675310&#39;</span><span class="p">,</span>
</span><span class="code-line">    <span class="k">array</span><span class="p">(</span>
</span><span class="code-line">        <span class="s1">&#39;from&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;+15017122661&#39;</span><span class="p">,</span>
</span><span class="code-line">        <span class="s1">&#39;body&#39;</span> <span class="o">=&gt;</span> <span class="s2">&quot;McAvoy or Stewart? These timelines can get so confusing.&quot;</span><span class="p">,</span>
</span><span class="code-line">        <span class="s1">&#39;statusCallback&#39;</span> <span class="o">=&gt;</span> <span class="s2">&quot;http://requestb.in/1234abcd&quot;</span>
</span><span class="code-line">    <span class="p">)</span>
</span><span class="code-line"><span class="p">);</span>
</span>
                

                    <span class="code-line"><span class="kn">from</span> <span class="nn">twilio.rest</span> <span class="kn">import</span> <span class="n">TwilioRestClient</span>
</span><span class="code-line">
</span><span class="code-line"><span class="c1"># put your own credentials here</span>
</span><span class="code-line"><span class="n">ACCOUNT_SID</span> <span class="o">=</span> <span class="s2">&quot;ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&quot;</span>
</span><span class="code-line"><span class="n">AUTH_TOKEN</span> <span class="o">=</span> <span class="s2">&quot;your_auth_token&quot;</span>
</span><span class="code-line">
</span><span class="code-line"><span class="n">client</span> <span class="o">=</span> <span class="n">TwilioRestClient</span><span class="p">(</span><span class="n">ACCOUNT_SID</span><span class="p">,</span> <span class="n">AUTH_TOKEN</span><span class="p">)</span>
</span><span class="code-line">
</span><span class="code-line"><span class="n">client</span><span class="o">.</span><span class="n">messages</span><span class="o">.</span><span class="n">create</span><span class="p">(</span>
</span><span class="code-line">    <span class="n">to</span><span class="o">=</span><span class="s2">&quot;+15558675310&quot;</span><span class="p">,</span>
</span><span class="code-line">    <span class="n">from_</span><span class="o">=</span><span class="s2">&quot;+15017122661&quot;</span><span class="p">,</span>
</span><span class="code-line">    <span class="n">body</span><span class="o">=</span><span class="s2">&quot;McAvoy or Stewart? These timelines can get so confusing.&quot;</span><span class="p">,</span>
</span><span class="code-line">    <span class="n">status_callback</span><span class="o">=</span><span class="s2">&quot;http://requestb.in/1234abcd&quot;</span>
</span><span class="code-line"><span class="p">)</span>
</span>
                

                    <span class="code-line"><span class="nb">require</span> <span class="s1">&#39;rubygems&#39;</span> <span class="c1"># not necessary with ruby 1.9 but included for completeness</span>
</span><span class="code-line"><span class="nb">require</span> <span class="s1">&#39;twilio-ruby&#39;</span>
</span><span class="code-line">
</span><span class="code-line"><span class="c1"># put your own credentials here</span>
</span><span class="code-line"><span class="n">account_sid</span> <span class="o">=</span> <span class="s1">&#39;ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&#39;</span>
</span><span class="code-line"><span class="n">auth_token</span> <span class="o">=</span> <span class="s1">&#39;your_auth_token&#39;</span>
</span><span class="code-line">
</span><span class="code-line"><span class="c1"># set up a client to talk to the Twilio REST API</span>
</span><span class="code-line"><span class="vi">@client</span> <span class="o">=</span> <span class="no">Twilio</span><span class="o">::</span><span class="no">REST</span><span class="o">::</span><span class="no">Client</span><span class="o">.</span><span class="n">new</span><span class="p">(</span><span class="n">account_sid</span><span class="p">,</span> <span class="n">auth_token</span><span class="p">)</span>
</span><span class="code-line">
</span><span class="code-line"><span class="vi">@client</span><span class="o">.</span><span class="n">messages</span><span class="o">.</span><span class="n">create</span><span class="p">(</span>
</span><span class="code-line">  <span class="ss">from</span><span class="p">:</span> <span class="s1">&#39;+15017122661&#39;</span><span class="p">,</span>
</span><span class="code-line">  <span class="ss">to</span><span class="p">:</span> <span class="s1">&#39;+15558675310&#39;</span><span class="p">,</span>
</span><span class="code-line">  <span class="ss">body</span><span class="p">:</span> <span class="s1">&#39;McAvoy or Stewart? These timelines can get so confusing.&#39;</span><span class="p">,</span>
</span><span class="code-line">  <span class="ss">status_callback</span><span class="p">:</span> <span class="s1">&#39;http://requestb.in/1234abcd&#39;</span>
</span><span class="code-line"><span class="p">)</span>
</span>
                

                    <span class="code-line"><span class="c1">// You may want to be more specific in your imports</span>
</span><span class="code-line"><span class="kn">import</span> <span class="nn">java.util.*</span><span class="p">;</span>
</span><span class="code-line"><span class="kn">import</span> <span class="nn">com.twilio.sdk.*</span><span class="p">;</span>
</span><span class="code-line"><span class="kn">import</span> <span class="nn">com.twilio.sdk.resource.factory.*</span><span class="p">;</span>
</span><span class="code-line"><span class="kn">import</span> <span class="nn">com.twilio.sdk.resource.instance.*</span><span class="p">;</span>
</span><span class="code-line"><span class="kn">import</span> <span class="nn">com.twilio.sdk.resource.list.*</span><span class="p">;</span>
</span><span class="code-line"><span class="kn">import</span> <span class="nn">java.util.ArrayList</span><span class="p">;</span>
</span><span class="code-line"><span class="kn">import</span> <span class="nn">java.util.List</span><span class="p">;</span>
</span><span class="code-line"><span class="kn">import</span> <span class="nn">org.apache.http.NameValuePair</span><span class="p">;</span>
</span><span class="code-line"><span class="kn">import</span> <span class="nn">org.apache.http.message.BasicNameValuePair</span><span class="p">;</span>
</span><span class="code-line">
</span><span class="code-line"><span class="kd">public</span> <span class="kd">class</span> <span class="nc">TwilioTest</span> <span class="p">{</span>
</span><span class="code-line"> <span class="c1">// Find your Account Sid and Token at twilio.com/user/account</span>
</span><span class="code-line"> <span class="kd">public</span> <span class="kd">static</span> <span class="kd">final</span> <span class="n">String</span> <span class="n">ACCOUNT_SID</span> <span class="o">=</span> <span class="s">&quot;ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&quot;</span><span class="p">;</span>
</span><span class="code-line"> <span class="kd">public</span> <span class="kd">static</span> <span class="kd">final</span> <span class="n">String</span> <span class="n">AUTH_TOKEN</span> <span class="o">=</span> <span class="s">&quot;your_auth_token&quot;</span><span class="p">;</span>
</span><span class="code-line">
</span><span class="code-line"> <span class="kd">public</span> <span class="kd">static</span> <span class="kt">void</span> <span class="nf">main</span><span class="p">(</span><span class="n">String</span><span class="o">[]</span><span class="n">args</span><span class="p">)</span> <span class="kd">throws</span> <span class="n">TwilioRestException</span> <span class="p">{</span>
</span><span class="code-line">  <span class="n">TwilioRestClient</span> <span class="n">client</span> <span class="o">=</span> <span class="k">new</span> <span class="n">TwilioRestClient</span><span class="p">(</span><span class="n">ACCOUNT_SID</span><span class="p">,</span> <span class="n">AUTH_TOKEN</span><span class="p">);</span>
</span><span class="code-line">
</span><span class="code-line">   <span class="c1">// Build the parameters</span>
</span><span class="code-line">   <span class="n">List</span><span class="o">&lt;</span><span class="n">NameValuePair</span><span class="o">&gt;</span> <span class="n">params</span> <span class="o">=</span> <span class="k">new</span> <span class="n">ArrayList</span><span class="o">&lt;</span><span class="n">NameValuePair</span><span class="o">&gt;</span><span class="p">();</span>
</span><span class="code-line">   <span class="n">params</span><span class="p">.</span><span class="na">add</span><span class="p">(</span><span class="k">new</span> <span class="n">BasicNameValuePair</span><span class="p">(</span><span class="s">&quot;To&quot;</span><span class="p">,</span> <span class="s">&quot;+15558675310&quot;</span><span class="p">));</span>
</span><span class="code-line">   <span class="n">params</span><span class="p">.</span><span class="na">add</span><span class="p">(</span><span class="k">new</span> <span class="n">BasicNameValuePair</span><span class="p">(</span><span class="s">&quot;From&quot;</span><span class="p">,</span> <span class="s">&quot;+15017122661&quot;</span><span class="p">));</span>
</span><span class="code-line">   <span class="n">params</span><span class="p">.</span><span class="na">add</span><span class="p">(</span><span class="k">new</span> <span class="n">BasicNameValuePair</span><span class="p">(</span><span class="s">&quot;Body&quot;</span><span class="p">,</span> <span class="s">&quot;McAvoy or Stewart? These timelines can get so confusing.&quot;</span><span class="p">));</span>
</span><span class="code-line">   <span class="n">params</span><span class="p">.</span><span class="na">add</span><span class="p">(</span><span class="k">new</span> <span class="n">BasicNameValuePair</span><span class="p">(</span><span class="s">&quot;StatusCallback&quot;</span><span class="p">,</span> <span class="s">&quot;http://requestb.in/1234abcd&quot;</span><span class="p">));</span>
</span><span class="code-line">
</span><span class="code-line">   <span class="n">MessageFactory</span> <span class="n">messageFactory</span> <span class="o">=</span> <span class="n">client</span><span class="p">.</span><span class="na">getAccount</span><span class="p">().</span><span class="na">getMessageFactory</span><span class="p">();</span>
</span><span class="code-line">   <span class="n">Message</span> <span class="n">message</span> <span class="o">=</span> <span class="n">messageFactory</span><span class="p">.</span><span class="na">create</span><span class="p">(</span><span class="n">params</span><span class="p">);</span>
</span><span class="code-line">   <span class="n">System</span><span class="p">.</span><span class="na">out</span><span class="p">.</span><span class="na">println</span><span class="p">(</span><span class="n">message</span><span class="p">.</span><span class="na">getSid</span><span class="p">());</span>
</span><span class="code-line"> <span class="p">}</span>
</span><span class="code-line"><span class="p">}</span>
</span>
                

                    <span class="code-line"><span class="kn">from</span> <span class="nn">twilio.rest</span> <span class="kn">import</span> <span class="n">Client</span>
</span><span class="code-line">
</span><span class="code-line"><span class="c1"># put your own credentials here</span>
</span><span class="code-line"><span class="n">account_sid</span> <span class="o">=</span> <span class="s2">&quot;ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&quot;</span>
</span><span class="code-line"><span class="n">auth_token</span> <span class="o">=</span> <span class="s2">&quot;your_auth_token&quot;</span>
</span><span class="code-line">
</span><span class="code-line"><span class="n">client</span> <span class="o">=</span> <span class="n">Client</span><span class="p">(</span><span class="n">account_sid</span><span class="p">,</span> <span class="n">auth_token</span><span class="p">)</span>
</span><span class="code-line">
</span><span class="code-line"><span class="n">client</span><span class="o">.</span><span class="n">messages</span><span class="o">.</span><span class="n">create</span><span class="p">(</span>
</span><span class="code-line">    <span class="n">to</span><span class="o">=</span><span class="s2">&quot;+15558675310&quot;</span><span class="p">,</span>
</span><span class="code-line">    <span class="n">from_</span><span class="o">=</span><span class="s2">&quot;+15017122661&quot;</span><span class="p">,</span>
</span><span class="code-line">    <span class="n">body</span><span class="o">=</span><span class="s2">&quot;McAvoy or Stewart? These timelines can get so confusing.&quot;</span><span class="p">,</span>
</span><span class="code-line">    <span class="n">status_callback</span><span class="o">=</span><span class="s2">&quot;http://requestb.in/1234abcd&quot;</span>
</span><span class="code-line"><span class="p">)</span>
</span>
                

                    <span class="code-line"><span class="c1">// Install the Java helper library from twilio.com/docs/java/install</span>
</span><span class="code-line"><span class="kn">import</span> <span class="nn">com.twilio.Twilio</span><span class="p">;</span>
</span><span class="code-line"><span class="kn">import</span> <span class="nn">com.twilio.rest.api.v2010.account.Message</span><span class="p">;</span>
</span><span class="code-line"><span class="kn">import</span> <span class="nn">com.twilio.type.PhoneNumber</span><span class="p">;</span>
</span><span class="code-line">
</span><span class="code-line"><span class="kd">public</span> <span class="kd">class</span> <span class="nc">Example</span> <span class="p">{</span>
</span><span class="code-line">  <span class="c1">// Find your Account Sid and Token at twilio.com/user/account</span>
</span><span class="code-line">  <span class="kd">public</span> <span class="kd">static</span> <span class="kd">final</span> <span class="n">String</span> <span class="n">ACCOUNT_SID</span> <span class="o">=</span> <span class="s">&quot;ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&quot;</span><span class="p">;</span>
</span><span class="code-line">  <span class="kd">public</span> <span class="kd">static</span> <span class="kd">final</span> <span class="n">String</span> <span class="n">AUTH_TOKEN</span> <span class="o">=</span> <span class="s">&quot;your_auth_token&quot;</span><span class="p">;</span>
</span><span class="code-line">
</span><span class="code-line">  <span class="kd">public</span> <span class="kd">static</span> <span class="kt">void</span> <span class="nf">main</span><span class="p">(</span><span class="n">String</span><span class="o">[]</span> <span class="n">args</span><span class="p">)</span> <span class="p">{</span>
</span><span class="code-line">    <span class="n">Twilio</span><span class="p">.</span><span class="na">init</span><span class="p">(</span><span class="n">ACCOUNT_SID</span><span class="p">,</span> <span class="n">AUTH_TOKEN</span><span class="p">);</span>
</span><span class="code-line">
</span><span class="code-line">    <span class="n">Message</span> <span class="n">message</span> <span class="o">=</span> <span class="n">Message</span><span class="p">.</span><span class="na">creator</span><span class="p">(</span>
</span><span class="code-line">      <span class="k">new</span> <span class="n">PhoneNumber</span><span class="p">(</span><span class="s">&quot;+15558675310&quot;</span><span class="p">),</span>
</span><span class="code-line">      <span class="k">new</span> <span class="n">PhoneNumber</span><span class="p">(</span><span class="s">&quot;+15017122661&quot;</span><span class="p">),</span>
</span><span class="code-line">      <span class="s">&quot;McAvoy or Stewart? These timelines can get so confusing.&quot;</span><span class="p">)</span>
</span><span class="code-line">        <span class="p">.</span><span class="na">setStatusCallback</span><span class="p">(</span><span class="s">&quot;http://requestb.in/1234abcd&quot;</span><span class="p">)</span>
</span><span class="code-line">        <span class="p">.</span><span class="na">create</span><span class="p">();</span>
</span><span class="code-line">
</span><span class="code-line">    <span class="n">System</span><span class="p">.</span><span class="na">out</span><span class="p">.</span><span class="na">println</span><span class="p">(</span><span class="n">message</span><span class="p">.</span><span class="na">getSid</span><span class="p">());</span>
</span><span class="code-line">  <span class="p">}</span>
</span><span class="code-line"><span class="p">}</span>
</span>
                

                    <span class="code-line"><span class="kn">import</span> <span class="nn">os</span>
</span><span class="code-line"><span class="kn">from</span> <span class="nn">twilio.rest</span> <span class="kn">import</span> <span class="n">Client</span>
</span><span class="code-line">
</span><span class="code-line"><span class="c1"># put your own credentials here</span>
</span><span class="code-line"><span class="c1"># To set up environmental variables, see http://twil.io/secure</span>
</span><span class="code-line"><span class="n">account_sid</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s1">&#39;TWILIO_ACCOUNT_SID&#39;</span><span class="p">]</span>
</span><span class="code-line"><span class="n">auth_token</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s1">&#39;TWILIO_AUTH_TOKEN&#39;</span><span class="p">]</span>
</span><span class="code-line">
</span><span class="code-line"><span class="n">client</span> <span class="o">=</span> <span class="n">Client</span><span class="p">(</span><span class="n">account_sid</span><span class="p">,</span> <span class="n">auth_token</span><span class="p">)</span>
</span><span class="code-line">
</span><span class="code-line"><span class="n">client</span><span class="o">.</span><span class="n">messages</span><span class="o">.</span><span class="n">create</span><span class="p">(</span>
</span><span class="code-line">    <span class="n">to</span><span class="o">=</span><span class="s2">&quot;+15558675310&quot;</span><span class="p">,</span>
</span><span class="code-line">    <span class="n">from_</span><span class="o">=</span><span class="s2">&quot;+15017122661&quot;</span><span class="p">,</span>
</span><span class="code-line">    <span class="n">body</span><span class="o">=</span><span class="s2">&quot;McAvoy or Stewart? These timelines can get so confusing.&quot;</span><span class="p">,</span>
</span><span class="code-line">    <span class="n">status_callback</span><span class="o">=</span><span class="s2">&quot;http://requestb.in/1234abcd&quot;</span>
</span><span class="code-line"><span class="p">)</span>
</span>
                

                    <span class="code-line"><span class="c1">// Install the Java helper library from twilio.com/docs/java/install</span>
</span><span class="code-line"><span class="kn">import</span> <span class="nn">com.twilio.Twilio</span><span class="p">;</span>
</span><span class="code-line"><span class="kn">import</span> <span class="nn">com.twilio.rest.api.v2010.account.Message</span><span class="p">;</span>
</span><span class="code-line"><span class="kn">import</span> <span class="nn">com.twilio.type.PhoneNumber</span><span class="p">;</span>
</span><span class="code-line">
</span><span class="code-line"><span class="kd">public</span> <span class="kd">class</span> <span class="nc">Example</span> <span class="p">{</span>
</span><span class="code-line">  <span class="c1">// Get your Account SID and Auth Token from https://twilio.com/console</span>
</span><span class="code-line">  <span class="c1">// To set up environment variables, see http://twil.io/secure</span>
</span><span class="code-line">  <span class="kd">public</span> <span class="kd">static</span> <span class="kd">final</span> <span class="n">String</span> <span class="n">ACCOUNT_SID</span> <span class="o">=</span> <span class="n">System</span><span class="p">.</span><span class="na">getenv</span><span class="p">(</span><span class="s">&quot;TWILIO_ACCOUNT_SID&quot;</span><span class="p">);</span>
</span><span class="code-line">  <span class="kd">public</span> <span class="kd">static</span> <span class="kd">final</span> <span class="n">String</span> <span class="n">AUTH_TOKEN</span> <span class="o">=</span> <span class="n">System</span><span class="p">.</span><span class="na">getenv</span><span class="p">(</span><span class="s">&quot;TWILIO_AUTH_TOKEN&quot;</span><span class="p">);</span>
</span><span class="code-line">
</span><span class="code-line">  <span class="kd">public</span> <span class="kd">static</span> <span class="kt">void</span> <span class="nf">main</span><span class="p">(</span><span class="n">String</span><span class="o">[]</span> <span class="n">args</span><span class="p">)</span> <span class="p">{</span>
</span><span class="code-line">    <span class="n">Twilio</span><span class="p">.</span><span class="na">init</span><span class="p">(</span><span class="n">ACCOUNT_SID</span><span class="p">,</span> <span class="n">AUTH_TOKEN</span><span class="p">);</span>
</span><span class="code-line">
</span><span class="code-line">    <span class="n">Message</span> <span class="n">message</span> <span class="o">=</span> <span class="n">Message</span><span class="p">.</span><span class="na">creator</span><span class="p">(</span>
</span><span class="code-line">      <span class="k">new</span> <span class="n">PhoneNumber</span><span class="p">(</span><span class="s">&quot;+15558675310&quot;</span><span class="p">),</span>
</span><span class="code-line">      <span class="k">new</span> <span class="n">PhoneNumber</span><span class="p">(</span><span class="s">&quot;+15017122661&quot;</span><span class="p">),</span>
</span><span class="code-line">      <span class="s">&quot;McAvoy or Stewart? These timelines can get so confusing.&quot;</span><span class="p">)</span>
</span><span class="code-line">        <span class="p">.</span><span class="na">setStatusCallback</span><span class="p">(</span><span class="s">&quot;http://requestb.in/1234abcd&quot;</span><span class="p">)</span>
</span><span class="code-line">        <span class="p">.</span><span class="na">create</span><span class="p">();</span>
</span><span class="code-line">
</span><span class="code-line">    <span class="n">System</span><span class="p">.</span><span class="na">out</span><span class="p">.</span><span class="na">println</span><span class="p">(</span><span class="n">message</span><span class="p">.</span><span class="na">getSid</span><span class="p">());</span>
</span><span class="code-line">  <span class="p">}</span>
</span><span class="code-line"><span class="p">}</span>
</span>
                

                    <span class="code-line">curl -X POST <span class="s1">&#39;https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages.json&#39;</span> <span class="se">\</span>
</span><span class="code-line">--data-urlencode <span class="s1">&#39;To=+15558675310&#39;</span>  <span class="se">\</span>
</span><span class="code-line">--data-urlencode <span class="s1">&#39;From=+15017122661&#39;</span>  <span class="se">\</span>
</span><span class="code-line">--data-urlencode <span class="s1">&#39;Body=McAvoy or Stewart? These timelines can get so confusing.&#39;</span>  <span class="se">\</span>
</span><span class="code-line">--data-urlencode <span class="s1">&#39;StatusCallback=http://requestb.in/1234abcd&#39;</span>  <span class="se">\</span>
</span><span class="code-line">-u ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token
</span>
                

配信性やエンゲージメントを把握・分析

コードサンプル

コードサンプルを使用して
一般的なユースケースを構築

SMS通知

サンプルアプリをご覧いただくと、TwilioのREST APIを利用しワークフローを自動化する方法が分かります。

C#, Java, Node.js, PHP, Python, Ruby

WhatsApp通知

WhatsApp Business APIを利用し、通知用メッセージテンプレートを作成することができます。

C#, Java, Node.js, PHP, Python, Ruby

SMS・MMS通知の
自動化

シンプルなWebアプリケーションを作成し、アラートメッセージを送信することができます。

C#, Java, Node.js, PHP, Python, Ruby

オムニチャネル通知

サンプルアプリはメール受信設定画面を搭載。ユーザーがさまざまなメッセージタイプを選択することができます。

C#, Java, Node.js, PHP, Python, Ruby

予約リマインダー

通知機能を構築し、顧客に予約のリマインダーを送信することができます。

C#, Java, Node.js, PHP, Python, Ruby

シンプルな一括アラート

シンプルな通知システムを設定し、重要なお知らせを瞬時に配信することが可能です。

C#, Java, Node.js, PHP, Python, Ruby

リードアラートの即時配信

リードアラートの即時配信用サンプルアプリを公開しています。営業プロセスの迅速化に活用ください。

C#, Java, Node.js, PHP, Python, Ruby

SMS・MMSの
マーケティングメッセージ

オプトイン顧客向けに、SMS・MMSのマーケティングメッセージを作成・配信することができます。

C#, Java, Node.js, PHP, Python, Ruby

始めましょう

使い慣れた開発言語を
お選びいただけます

参考資料

SMSクイックスタート

クイックガイドを見ながら、開発言語別にメッセージ送信方法を学べます。

SMSを始める

Twilioは、WhatsApp Business APIにも対応

Twilio APIの知識をもとに、WhatsAppの機能を簡単に追加することができます。

WhatsAppを始める

メッセージの配信ステータス追跡

WebアプリからProgrammable Messagingを使用しメッセージを送信した場合、配信ステータスを追跡することができます。

チュートリアルはこちら

メッセージを受信し、返信する

Programmable Messagingを使用し、受信したSMSメッセージにWebアプリから返信する方法です。

チュートリアルはこちら

APIリファレンス

Programmable Messaging API

Programmable Messaging APIを使用し、ご使用のアプリケーションに、強力なメッセージング機能を追加できます。

ドキュメントはこちら

WhatsApp Business API

REST APIを1つ使用するだけで、メッセージングアプリWhatsAppからの送信が可能になります。

ドキュメントはこちら

料金

多彩な料金プラン

いずれもシンプルな料金プランをご用意。従量課金、ボリュームディスカウント、1か月の使用量に基づく確約利用割引からお選びいただけます。

Twilioが選ばれる理由

Twilioはあらゆる構築、効率的なコーディングが可能。

クラス最高レベルのチャネルAPIが、あらゆるチャネルのコミュニケーション品質を確保

グローバルな顧客リーチと圧倒的な規模により、

800万人の開発者をサポート

高性能サーバーレスツールとフルプログラム可能なソリューションが、数分で実装可能

エンタープライズクラスのセキュリティと信頼性が、19万以上の優良ブランドをサポート