1

Webアプリケーションで音声通話を使用しようとしています。 は、我々はコードの下に使用してみました:Webアプリケーションでtwiloを使用した音声通話

コードの上から
public class MakeCall { 
    public static final String ACCOUNT_SID = "ACbXXXXXXXXXXXXXXXXXXXXXXXX"; 
    public static final String AUTH_TOKEN = "545XXXXXXXXXXXXXXXXXXXXXXXX"; 
    public static final String TWILIO_NUMBER = "+185XXXXXXXXX"; 
    public static void main(String[] args) throws TwilioRestException { 
    TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN); 
    Account mainAccount = client.getAccount(); 
    CallFactory callFactory = mainAccount.getCallFactory(); 
    Map<String, String> callParams = new HashMap<String, String>(); 
    callParams.put("From",TWILIO_NUMBER); 
    callParams.put("To", "+919014512394"); 
    callParams.put("Url", "http://ahoy.twilio.com/voice/api/demo"); 
    Call call = callFactory.create(callParams); 
    System.out.println(call.getSid()); 
    } 
} 

は、我々はTwilioの音声デモアプリケーションへようこそすなわちtwilio顧客の声を聞くことができます。明日の天気予報を聞くには1を押してください。 2を押して曲を聴く。 3を押して会議ブリッジを作成または参加します。音声を5秒間録音するには、4を押します。

は、実は私たちは基本的に私たちは私たちに アドバンスのおかげでここ

答えて

0

Twilioの開発者エバンジェリストを導くAPI.Plz twilioに慣れていtwilio番号

から呼び出すことにより、他の携帯電話番号と話をしたいと思います。

作成したコードは、そのエンドポイントを呼び出すと新しい呼び出しを開始します。新しい通話を開始してから別の番号に接続して2人で通話できるようにするには、少し変更する必要があります。Dials番号を変更してください。

ここでは、話したい相手を選んでその人にダイヤルする方法を示しています。

package com.twilio; 

import com.twilio.twiml.Gather; 
import com.twilio.twiml.Method; 
import com.twilio.twiml.Play; 
import com.twilio.twiml.Say; 
import com.twilio.twiml.TwiMLException; 
import com.twilio.twiml.VoiceResponse; 

import javax.servlet.http.HttpServlet; 
import javax.servlet.http.HttpServletRequest; 
import javax.servlet.http.HttpServletResponse; 
import java.io.IOException; 
import java.util.HashMap; 

public class TwilioServlet extends HttpServlet { 

    public void service(HttpServletRequest request, HttpServletResponse response) throws IOException { 
     // Create a dict of people we know. 
     HashMap<String, String> callers = new HashMap<String, String>(); 
     callers.put("+14158675309", "Curious George"); 
     callers.put("+14158675310", "Boots"); 
     callers.put("+14158675311", "Virgil"); 

     String fromNumber = request.getParameter("From"); 
     String knownCaller = callers.get(fromNumber); 
     String message; 
     if (knownCaller == null) { 
      // Use a generic message 
      message = "Hello Monkey"; 
     } else { 
      // Use the caller's name 
      message = "Hello " + knownCaller; 
     } 

     // Create a TwiML response and add our friendly message. 
     VoiceResponse twiml = new VoiceResponse.Builder() 
       .say(new Say.Builder(message).build()) 
       // Play an MP3 for incoming callers. 
       .play(new Play.Builder("http://demo.twilio.com/hellomonkey/monkey.mp3").build()) 
       .gather(new Gather.Builder() 
         .action("/handle-key") 
         .method(Method.POST) 
         .numDigits(1) 
         .say(new Say 
           .Builder("To speak to a real monkey, press 1. Press any other key to start over.") 
           .build()) 
         .build() 
       ) 
       .build(); 

     response.setContentType("application/xml"); 
     try { 
      response.getWriter().print(twiml.toXml()); 
     } catch (TwiMLException e) { 
      e.printStackTrace(); 
     } 
    } 
} 
  1. あなたが番号を押すと、すべてのあなたの電話番号
  2. を含むHashMapのから始め、/ハンドルキーのエンドポイントが呼び出されます。別の番号をダイヤルするためのロジックが必要ですこのの完全な説明を読み、このquickstartの他の例を見つけることができます

    package com.twilio; 
    
    import com.twilio.twiml.Dial; 
    import com.twilio.twiml.Number; 
    import com.twilio.twiml.Say; 
    import com.twilio.twiml.TwiMLException; 
    import com.twilio.twiml.VoiceResponse; 
    
    import javax.servlet.http.HttpServlet; 
    import javax.servlet.http.HttpServletRequest; 
    import javax.servlet.http.HttpServletResponse; 
    import java.io.IOException; 
    
    public class TwilioHandleKeyServlet extends HttpServlet { 
    
        @Override 
        public void service(HttpServletRequest request, HttpServletResponse response) throws IOException { 
    
         String digits = request.getParameter("Digits"); 
         VoiceResponse twiml; 
         // Check if the user pressed "1" on their phone 
         if (digits != null && digits.equals("1")) { 
          // Connect 310 555 1212 to the incoming caller. 
          Number number = new Number.Builder("+13105551212").build(); 
          Dial dial = new Dial.Builder().number(number).build(); 
    
          // If the above dial failed, say an error message. 
          Say say = new Say.Builder("The call failed, or the remote party hung up. Goodbye.").build(); 
    
          twiml = new VoiceResponse.Builder().dial(dial).say(say).build(); 
         } else { 
          // If they didn't press 1, redirect them to the TwilioServlet 
          response.sendRedirect("/twiml"); 
          return; 
         } 
    
         response.setContentType("application/xml"); 
         try { 
          response.getWriter().print(twiml.toXml()); 
         } catch (TwiMLException e) { 
          e.printStackTrace(); 
         } 
        } 
    } 
    

起こる場所です。

これがあなたを助けてくれることを願っています。

関連する問題