メニュー

Rate this page:

Thanks for rating this page!

We are always striving to improve our documentation quality, and your feedback is valuable to us. How could this documentation serve you better?

Programmable Fax クイックスタート

Twilio's Programmable Fax lets you send, receive, and manage faxes in your web applications with just a few lines of code.

This Python SMS Quickstart will teach you the basics of fax using our Communications REST API and either cURL or your choice of language helper library. This quickstart includes detailed instructions for those helper libraries in your choice of Python, PHP, C#, Node.js, Java, and Ruby.

このクイックスタートでは、下記のことを学んでいきます:

  1. Sign up for Twilio and get your first Fax-enabled Twilio phone number
  2. Set up your development environment to send and receive faxes
  3. Send your first fax
  4. FAXを受信する

はじめましょう!

I'm ready to get my fax on!

はじめましょう

Before you can commence world domination via facsimile, you'll need to own a Twilio phone number capable of sending and receiving faxes. In the Twilio Console (sign up for a Twilio account if you haven't already), you can search for phone numbers capable of sending and receiving faxes.

FAX送受信対応電話番号を探す

リストから該当の番号に表示されている Buy ボタンをクリックして電話番号を取得します。

FAX送受信対応電話番号を取得する

これでFAX送受信対応電話番号が取得できました。それでは、どのようにREST APIを使ってFAXを送信するのか見ていきましょう。

今すぐにでもFAXを送信したい!

FAXの送信

Sending a fax requires a Twilio Account SID and Auth Token. You can find your credentials on the Console dashboard. Your API request will use these credentials for HTTP basic authentication. There are three parameters that you must also pass along with your request.

  1. From FAX送信者番号として通知するTwilio電話番号。ご自身で取得しているFAX送受信対応Twilio電話番号のうちの1つを指定します。
  2. To FAXの送信先電話番号。
  3. MediaUrl 送信内容が保存されたPDFファイルまでの完全URL。

Note: You should pass your phone numbers to the API in the E.164 format. For our cURL example we manually encoded the "+" sign at the beginning of each phone number to its encoded value, "%2B".

Another Note: Please make sure you are using the latest version of your favorite language's Twilio helper library.

        
        
        
        
        Code to send a fax with cURL or your choice of web language.

        FAXの送信

        Code to send a fax with cURL or your choice of web language.

        Within moments of running the above code, your fax should be happily on its way to a lucky recipient. To get updated on the status of the fax (including when sending failed), you can specify a StatusCallback parameter in your request to provide a URL which will be requested when the status of an outbound fax changes.

        That was faxcinating. How can I receive faxes?

        FAXを受信する

        When your Twilio number receives an incoming fax, Twilio will send an HTTP request to a server you control. This callback mechanism is known as a webhook. When Twilio sends your application a request, it expects a response in the TwiML XML format telling it how to respond to the message.

        Here's an example of a simple web application set up to receive a fax demonstrating our helper libraries in a variety of web languages.

              
              
              
              
              Code to receive an incoming fax with a selection of languages and web frameworks.

              FAXを受信する

              Code to receive an incoming fax with a selection of languages and web frameworks.

              There are two routes you'll probably need in your application:

              1. One to return TwiML when the fax is initially sent to your number
              2. A second when the fax has completed sending

              Before we can start directing Twilio how to handle our faxes,

              開発やテスト中の方は、おそらくこのコードを localhost (LAN内)で動かしているかもしれません。残念ながら、TwilioはみなさんのLAN内にあるホストを直接呼び出すことはできません。このコードをパブリックネットワークからアクセスできるサーバーに配置するか、ngrokのように、インターネットからアクセスできるURLを使ったトンネル通信が可能な手法を取る必要があります。これから、どのようにそれをセットアップするか説明します。

              TwilioからLAN内ホストにアクセスさせる

              TwilioからLAN内ホストにアクセスを許可する

              If you haven't already, install ngrok and ensure the ngrok command is on your system path (or runnable on your Windows machine).

              The following command would use ngrok to expose port 3000 to the public Internet from the command line in Mac OSX or a *NIX flavor. Replace 3000 with whatever port number you're using to run your web application.

              ngrok http 3000
              

              Next, you'll see a screen similar to the following:

              ngrokのターミナル出力

              Now we have a new external URL, visibly on the public internet.

              Configure this address as the webhook for one of your phone numbers in the console. Select your phone number of choice then change the "A FAX COMES IN" field to the external URL to your service. For example in this case: https://sadfs3423.ngrok.io/fax/sent.

              FAX用のWebhook設定

              Now, you're all wired up - time to try it out...

              Send a fax to your Twilio phone number – if you're watching ngrok, you should see a pair of HTTP requests in the ngrok console. If everything worked, you should have printed the URL of a PDF containing your inbound fax to the console.

              Amazing! Where do I go from here?

              次のステップ

              Now that you understand the basics of sending and receiving faxes, you can check out the Fax REST API reference, or dive deeper into TwiML and webhooks to understand the lifecycle of receiving faxes via HTTP requests.

              Happy faxing!

              Rate this page:

              ヘルプが必要ですか?

              We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd browsing the Twilio tag on Stack Overflow.