当前位置: 首页>>代码示例>>Java>>正文


Java TwiMLResponse类代码示例

本文整理汇总了Java中com.twilio.sdk.verbs.TwiMLResponse的典型用法代码示例。如果您正苦于以下问题:Java TwiMLResponse类的具体用法?Java TwiMLResponse怎么用?Java TwiMLResponse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


TwiMLResponse类属于com.twilio.sdk.verbs包,在下文中一共展示了TwiMLResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: service

import com.twilio.sdk.verbs.TwiMLResponse; //导入依赖的package包/类
@Override
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
	String query = request.getParameter("Body");
	if (Strings.isNullOrEmpty(query)) {
		// Empty request
		return;
	}
	String openApiResponse = sendRequestToApiAi(query, request.getParameterMap());

	TwiMLResponse twiml = new TwiMLResponse();
	Message message = new Message(openApiResponse);
	try {
		twiml.append(message);
	} catch (TwiMLException e) {
		LOGGER.error(e.getMessage());
	}

	response.setContentType("application/xml");
	response.getWriter().print(twiml.toXML());
}
 
开发者ID:dialogflow,项目名称:dialogflow-java-client,代码行数:21,代码来源:TwilioSmsServlet.java

示例2: service

import com.twilio.sdk.verbs.TwiMLResponse; //导入依赖的package包/类
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
    // Create a dict of people we know.
    HashMap<String, String> people = new HashMap<String, String>();
    people.put("+14158675308", "Curious George");
    people.put("+14158675310", "Boots");
    people.put("+14158675311", "Virgil");

    // if the sender is known, then greet them by name
    String fromNumber = request.getParameter("From");
    String name = fromNumber != null && people.get(fromNumber) != null
        ? people.get(fromNumber)
        : "Monkey";

    TwiMLResponse twiml = new TwiMLResponse();
    try {
        twiml.append(new Say(String.format("Hello! %s", name)));
        twiml.append(new Sms(String.format("%s, thanks for the call!", name)));
    } catch (TwiMLException e) {
        e.printStackTrace();
    }

    response.setContentType("application/xml");
    response.getWriter().print(twiml.toXML());
}
 
开发者ID:TwilioDevEd,项目名称:api-snippets,代码行数:25,代码来源:SendSmsDuringCall.6.x.java

示例3: service

import com.twilio.sdk.verbs.TwiMLResponse; //导入依赖的package包/类
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
    // Create a dict of people we know.
    HashMap<String, String> people = new HashMap<String, String>();
    people.put("+14158675308", "Curious George");
    people.put("+14158675310", "Boots");
    people.put("+14158675311", "Virgil");

    // if the sender is known, then greet them by name
    String fromNumber = request.getParameter("From");
    String name = fromNumber != null && people.get(fromNumber) != null
        ? people.get(fromNumber)
        : "Monkey";
    String message =String.format("%s, thanks for the message!", name);

    TwiMLResponse twiml = new TwiMLResponse();

    try {
        twiml.append(new Message(message));
    } catch (TwiMLException e) {
        e.printStackTrace();
    }

    response.setContentType("application/xml");
    response.getWriter().print(twiml.toXML());
}
 
开发者ID:TwilioDevEd,项目名称:api-snippets,代码行数:26,代码来源:ReplyByName.6.x.java

示例4: service

import com.twilio.sdk.verbs.TwiMLResponse; //导入依赖的package包/类
@Override
public void service(final HttpServletRequest request, final HttpServletResponse response) throws IOException {
  TwiMLResponse twiml = new TwiMLResponse();
  Say say = new Say("You will now be connected to the first caller in the queue.");
  Dial dial = new Dial();
  Queue queueInDial = new Queue("Queue Demo");
  Redirect redirect = new Redirect();

  try {
    twiml.append(say);
    twiml.append(dial);
    dial.append(queueInDial);
    twiml.append(redirect);
  } catch (final TwiMLException e) {
      e.printStackTrace();
  }

  return twiml.toXML();
}
 
开发者ID:TwilioDevEd,项目名称:api-snippets,代码行数:20,代码来源:queue-redirect.6.x.java

示例5: service

import com.twilio.sdk.verbs.TwiMLResponse; //导入依赖的package包/类
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
    TwiMLResponse twiml = new TwiMLResponse();
    try {
        String to = request.getParameter("To");
        if (to != null) {
            Dial dial = new Dial();
            dial.setCallerId("+15017122661");
            dial.append(new Number(to));
            twiml.append(dial);
        } else {
            twiml.append(new Say("Thanks for calling!"));
        }
    } catch (TwiMLException e) {
        e.printStackTrace();
    }

    response.setContentType("application/xml");
    response.getWriter().print(twiml.toXML());
}
 
开发者ID:TwilioDevEd,项目名称:api-snippets,代码行数:20,代码来源:response-twiml-dial.6.x.java

示例6: service

import com.twilio.sdk.verbs.TwiMLResponse; //导入依赖的package包/类
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {

        // Create a TwiML response and add our friendly message.
        TwiMLResponse twiml = new TwiMLResponse();
        Say say = new Say("Hello. It's me.");
        Play play = new Play("http://howtodocs.s3.amazonaws.com/ahoyhoy.mp3");
        try {
            twiml.append(say);
            twiml.append(play);
        } catch (TwiMLException e) {
            e.printStackTrace();
        }

        response.setContentType("application/xml");
        response.getWriter().print(twiml.toXML());
    }
 
开发者ID:TwilioDevEd,项目名称:api-snippets,代码行数:17,代码来源:twiml-play.6.x.java

示例7: service

import com.twilio.sdk.verbs.TwiMLResponse; //导入依赖的package包/类
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {

        String recordingUrl = request.getParameter("RecordingUrl");
        TwiMLResponse twiml = new TwiMLResponse();
        if (recordingUrl != null) {
            try {
                twiml.append(new Say("Listen to your recorded message."));
                twiml.append(new Play(recordingUrl));
                twiml.append(new Say("Goodbye"));
            } catch (TwiMLException e) {
                e.printStackTrace();
            }
        } else {
            response.sendRedirect("/twiml");
            return;
        }

        response.setContentType("application/xml");
        response.getWriter().print(twiml.toXML());
    }
 
开发者ID:TwilioDevEd,项目名称:api-snippets,代码行数:21,代码来源:twiml-record.6.x.java

示例8: service

import com.twilio.sdk.verbs.TwiMLResponse; //导入依赖的package包/类
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
    String body = request.getParameter("Body");
    String message;
    if (body == "hello") {
        // Use a generic message
        message = "Hi there!";
    } else if (body == "bye") {
        // Use the caller's name
        message = "Goodbye!";
    }

    // Create a TwiML response and add our friendly message.
    TwiMLResponse twiml = new TwiMLResponse();
    Message sms = new Message(message);
    try {
        twiml.append(sms);
    } catch (TwiMLException e) {
        e.printStackTrace();
    }

    response.setContentType("application/xml");
    response.getWriter().print(twiml.toXML());
}
 
开发者ID:TwilioDevEd,项目名称:api-snippets,代码行数:24,代码来源:generate-twiml-dynamic-sms.6.x.java

示例9: service

import com.twilio.sdk.verbs.TwiMLResponse; //导入依赖的package包/类
@Override
public void service(final HttpServletRequest request, final HttpServletResponse response) throws IOException {
  final TwiMLResponse twiml = new TwiMLResponse();
  final Enqueue enqueue = new Enqueue();
  enqueue.setWorkflowSid("WW0123456789abcdef0123456789abcdef");

  final com.twilio.sdk.verbs.Task task = new com.twilio.sdk.verbs.Task("{\"account_number\":\"12345abcdef\"}");
  task.setPriority(5);
  task.setTimeout(200);

  try {
      enqueue.append(task);
      twiml.append(enqueue);
  } catch (final TwiMLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
  }

  return twiml.toXML();
}
 
开发者ID:TwilioDevEd,项目名称:api-snippets,代码行数:21,代码来源:example.6.x.java

示例10: service

import com.twilio.sdk.verbs.TwiMLResponse; //导入依赖的package包/类
@Override
public void service(final HttpServletRequest request, final HttpServletResponse response) throws IOException {
  final TwiMLResponse twiml = new TwiMLResponse();
  final Enqueue enqueue = new Enqueue();
  enqueue.setWorkflowSid("WW0123456789abcdef0123456789abcdef");
  enqueue.setWaitUrl("/hold_music.php");
  enqueue.setAction("/post_bridge_survey.php");

  final com.twilio.sdk.verbs.Task task = new com.twilio.sdk.verbs.Task("{\"account_number\":\"12345abcdef\"}");

  try {
      enqueue.append(task);
      twiml.append(enqueue);
  } catch (final TwiMLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
  }

  return twiml.toXML();
}
 
开发者ID:TwilioDevEd,项目名称:api-snippets,代码行数:21,代码来源:example.6.x.java

示例11: service

import com.twilio.sdk.verbs.TwiMLResponse; //导入依赖的package包/类
@Override
public void service(final HttpServletRequest request, final HttpServletResponse response) throws IOException {
  final TwiMLResponse twiml = new TwiMLResponse();
  final Enqueue enqueue = new Enqueue();
  enqueue.setWorkflowSid("WW0123456789abcdef0123456789abcdef");

  final com.twilio.sdk.verbs.Task task = new com.twilio.sdk.verbs.Task("{\"account_number\":\"12345abcdef\"}");

  try {
      enqueue.append(task);
      twiml.append(enqueue);
  } catch (final TwiMLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
  }

  return twiml.toXML();
}
 
开发者ID:TwilioDevEd,项目名称:api-snippets,代码行数:19,代码来源:example.6.x.java

示例12: main

import com.twilio.sdk.verbs.TwiMLResponse; //导入依赖的package包/类
public static void main(String[] args) {
    TwiMLResponse twiml = new TwiMLResponse();
    try {
        Say say = new Say("Welcome to Twilio, please tell us why you're calling");
        Gather gather = new Gather();
        gather.setAction("/completed");
        gather.set("input", "speech");
        gather.append(say);

        twiml.append(gather);
    } catch (TwiMLException e) {
        e.printStackTrace();
    }

    System.out.println(twiml.toXML());
}
 
开发者ID:TwilioDevEd,项目名称:api-snippets,代码行数:17,代码来源:gather-say-twiml.6.x.java

示例13: main

import com.twilio.sdk.verbs.TwiMLResponse; //导入依赖的package包/类
public static void main(String[] args) {
    // Create a TwiML builder object
    TwiMLResponse twiml = new TwiMLResponse();
    try {
        Message message = new Message();
        Body body = new Body("Hello friend");
        Media media = new Media("https://demo.twilio.com/owl.png");
        message.append(body);
        message.append(media);

        twiml.append(message);
    } catch (TwiMLException e) {
        e.printStackTrace();
    }

    System.out.println(twiml.toXML());
}
 
开发者ID:TwilioDevEd,项目名称:api-snippets,代码行数:18,代码来源:send-mms-twiml.6.x.java

示例14: doPost

import com.twilio.sdk.verbs.TwiMLResponse; //导入依赖的package包/类
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {

        // Create a TwiML response and add our friendly message.
        TwiMLResponse twiml = new TwiMLResponse();

        Gather gather = new Gather();
        gather.setNumDigits(1);
        try {
            gather.append(new Say("For sales, press 1. For support, press 2."));
            twiml.append(gather);
            twiml.append(new Redirect("/voice"));
        } catch (TwiMLException e) {
            throw new RuntimeException(e);
        }

        response.setContentType("application/xml");
        response.getWriter().print(twiml.toXML());
    }
 
开发者ID:TwilioDevEd,项目名称:api-snippets,代码行数:19,代码来源:example.6.x.java

示例15: service

import com.twilio.sdk.verbs.TwiMLResponse; //导入依赖的package包/类
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {

        // Create a TwiML response and add our friendly message.
        TwiMLResponse twiml = new TwiMLResponse();

        Gather gather = new Gather();
        gather.setNumDigits(1);
        try {
            gather.append(new Say("For sales, press 1. For support, press 2."));
            twiml.append(gather);
            twiml.append(new Redirect("/voice"));
        } catch (TwiMLException e) {
            throw new RuntimeException(e);
        }

        response.setContentType("application/xml");
        response.getWriter().print(twiml.toXML());
    }
 
开发者ID:TwilioDevEd,项目名称:api-snippets,代码行数:19,代码来源:example.6.x.java


注:本文中的com.twilio.sdk.verbs.TwiMLResponse类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。