<?php// Include the Twilio PHP libraryrequire "Services/Twilio.php"; // Set your AccountSid and AuthToken from www.twilio.com/user/account$AccountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";$AuthToken = "YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY"; // Instantiate a new Twilio Rest Client$client = new Services_Twilio($AccountSid, $AuthToken); // Make an array of people we know, to send them a message:$people = array( "+14158675309" => "Curious George", "+14158675310" => "Boots", "+14158675311" => "Virgil",); // Loop over all our friends:foreach ($people as $number => $name) { $sms = $client->account->sms_messages->create( "YYY-YYY-YYYY", // Change the 'From' number to a Twilio number you've purchased $number, // the number we are sending to - Any phone number "Hey $name, Monkey Party at 6PM. Bring Bananas!" // the sms body ); echo "Sent message to $name"; // Display a confirmation message}
application: examplehelloworldversion: 1runtime: phpapi_version: 1threadsafe: true handlers:- url: .* script: main.php
application: examplehelloworldversion: 1runtime: phpapi_version: 1threadsafe: true handlers:- url: /images static_dir: images - url: /send-sms script: send-sms.php - url: /make-call script: make-call.php - url: .* script: index.php
<?php require 'Services/Twilio.php';include 'credentials.php'; $client = new Services_Twilio($AccountSid, $AuthToken); $call = $client->account->calls->create( '1512-555-1212', // From this number '17035551212', // Send to this number 'http://twimlets.com/echo?Twiml=%3CResponse%3E%3CSay%3EHello%20Monkey!%3C%2FSay%3E%3C%2FResponse%3E&');print $call->sid;
<?php require 'Services/Twilio.php';include 'credentials.php'; $client = new Services_Twilio($AccountSid, $AuthToken); $call = $client->account->sms_messages->create( '1512-555-1212', // From this number '17035551212', // Send to this number 'Hello monkey!!');print $call->sid;
TwilioRestClient client = new TwilioRestClient("ACCOUNT_SID", "AUTH_TOKEN");Map params = new HashMap();params.put("Body", messageBody);params.put("To", sub);params.put("From", "+16122948105");SmsFactory messageFactory = client.getAccount().getSmsFactory();try {Sms message = messageFactory.create(params);System.out.println(message.getSid());} catch (TwilioRestException e) {e.printStackTrace();}
public class TwilioSmsServlet extends HttpServlet { // Handle Incoming SMS public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException { try { TwiMLResponse twiml = new TwiMLResponse(); // parse the body, looking for a command String smsBody = request.getParameter("Body"); String smsFrom = request.getParameter("From"); // Unsubscribe, if requested if (smsBody.startsWith("STOP")) { MultichannelChatManager.removeSub(smsFrom); com.twilio.sdk.verbs.Sms bye = new com.twilio.sdk.verbs.Sms("You have been unsubscribed. Thank You!"); twiml.append(bye); } else { // If they aren't subscribed, subscribe them if (!MultichannelChatManager.isSubscribed(smsFrom)) { MultichannelChatManager.addSub(smsFrom); } MultichannelChatManager.sendMessage(smsBody, "sms"); } response.setContentType("application/xml"); response.getWriter().print(twiml.toXML()); } catch (Exception e) { e.printStackTrace(); System.out.println(e); } }}
public class XMPPReceiverServlet extends HttpServlet { // Handle Incoming XMPP Chat messages public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException { XMPPService xmpp = XMPPServiceFactory.getXMPPService(); Message msg = xmpp.parseMessage(req); // The "JID" is the unique ID of this chat client, which we use to subscribe JID fromJid = msg.getFromJid(); String body = msg.getBody(); // Unsubscribe, if requested if (body.startsWith("STOP")) { MultichannelChatManager.removeSub(fromJid.getId()); } else { // If they aren't subscribed, subscribe them if (!MultichannelChatManager.isSubscribed(fromJid.getId())) { MultichannelChatManager.addSub(fromJid.getId()); } MultichannelChatManager.sendMessage(body, "xmpp"); } }}
JID jid = new JID(sub);Message msg = new MessageBuilder().withRecipientJids(jid).withBody(messageBody).build();XMPPService xmpp = XMPPServiceFactory.getXMPPService();xmpp.sendMessage(msg);
//Generate a client token for the GAE Channel APIpublic void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException { ChannelService channelService = ChannelServiceFactory.getChannelService(); //The token must be based on some unique identifier for the client - I am using the current time //for demo purposes... String clientId = String.valueOf(System.currentTimeMillis()); String token = channelService.createChannel(clientId); //Subscribe this client MultichannelChatManager.addSub(clientId); //Reply with the token res.setContentType("text/plain"); res.getWriter().print(token);}
//Get a client token to use with the channel API$.ajax('/chat',{ method:'GET', dataType:'text', success: function(token) { console.log(token); var channel = new goog.appengine.Channel(token); var socket = channel.open(); //Assign our handler function to the open socket socket.onmessage = onMessage; }});
ChannelService channelService = ChannelServiceFactory.getChannelService();channelService.sendMessage(new ChannelMessage(sub,messageBody));
from sendgrid import Sendgridfrom sendgrid import Message
# make a secure connection to SendGrids = sendgrid.Sendgrid('', '', secure=True)# make a message objectmessage = sendgrid.Message("from@mydomain.com", "message subject", "plaintext message body", "<strong>HTML message body</strong>")# add a recipientmessage.add_to("someone@example.com", "John Doe")# use the Web API to send your messages.web.send(message)
Use promo code NEXT1720 to save $300 off general admission