Using Twilio with Classic ASP and VBScript

Asp-logoWe’ve recently had an influx of requests for examples showing how to use Twilio with Classic ASP and VBScript. Here are two short examples to demonstrate how to initiate call and send a text message. You can download both files here.

Placing a Call via the REST API with Classic ASP

Let’s start off with an example for placing a call via the REST API. Initiating a call requires making a simple POST request. Let’s take a look at the code to make that happen.

Sending an SMS text message via the REST API

Sending an SMS is straightforward as well:

There you have it! If you have any questions about these examples, head on over to our forums or send us an email at help@twilio.com and we’ll be glad to help!

  • http://jamoramaexposed.com Fiona Smithe

    Easy option to get useful information as well as share good stuff with good ideas and concepts.

  • http://jamoramaexposed.com Fiona Smithe

    Easy option to get useful information as well as share good stuff with good ideas and concepts.

  • Mark

    Perfect, thanks! Big time saver. We’re not all using the latest and greatest technologies (Twilio excluded of course). This helps me use Twilio with my old school applications.

  • Mark

    Perfect, thanks! Big time saver. We’re not all using the latest and greatest technologies (Twilio excluded of course). This helps me use Twilio with my old school applications.

  • http://www.home-phone.com John Kulnis

    Here is the same in ASP and Javascript. Sometimes an error occurs that the SMS is not sent, but there is a delay and it gets sent.
    var objHTTP = Server.CreateObject(“MSXML2.XMLHTTP”);
    var vURL = “https://api.twilio.com/2010-04-01/Accounts/323232323/SMS/Messages”
    var vFrom = Server.URLEncode(“14150000000”)
    var vTo = Server.URLEncode(“15553331111”)
    var SMSInfo = Server.URLEncode(“My Text Message”)
    var vBotAll = “From=” + vFrom + “&To=” + vTo + “&Body=” + SMSInfo
    var AuthSID = “222222222” /// AuthSID
    var AuthToken = “3333333333” // AuthToken
    objHTTP.Open(“POST”, vURL, false, AuthSID, AuthToken)
    objHTTP.setRequestHeader(“Content-type”, “application/x-www-form-urlencoded”)
    objHTTP.Send(vBotAll)
    objHTTP = null

  • http://www.home-phone.com John Kulnis

    Here is the same in ASP and Javascript. Sometimes an error occurs that the SMS is not sent, but there is a delay and it gets sent.
    var objHTTP = Server.CreateObject(“MSXML2.XMLHTTP”);
    var vURL = “https://api.twilio.com/2010-04-01/Accounts/323232323/SMS/Messages”
    var vFrom = Server.URLEncode(“14150000000”)
    var vTo = Server.URLEncode(“15553331111”)
    var SMSInfo = Server.URLEncode(“My Text Message”)
    var vBotAll = “From=” + vFrom + “&To=” + vTo + “&Body=” + SMSInfo
    var AuthSID = “222222222” /// AuthSID
    var AuthToken = “3333333333” // AuthToken
    objHTTP.Open(“POST”, vURL, false, AuthSID, AuthToken)
    objHTTP.setRequestHeader(“Content-type”, “application/x-www-form-urlencoded”)
    objHTTP.Send(vBotAll)
    objHTTP = null

  • Brad

    This is great…what would the recipient format be for multiple numbers?

    • Dave

      i’m looking for an answer to this as well

  • Brad

    This is great…what would the recipient format be for multiple numbers?

  • Animesh Patra

    I have used this the above code for call, but i didn’t get any response in browser. but call goes to mobile. how to start call and stop call to mobile from browser in classic asp?

    • Devin Rader

      @animesh: The code above simply shows you how to initiate an outbound phone call from Twilio to a phone number. The URL that you specify in the Url parameter needs to return some TwiML (http://www.twilio.com/docs/api/twiml) that tells Twilio how to proceed with the call once the person you’re calling answers. The code above does not actually place a phone call from your browser to the mobile device, it simply tells Twilio to initiate a phone call from our servers to the phone number you’ve specified. If you want to create a phone in your browser you would need to use the Twilio Client (http://www.twilio.com/client) Javascript SDK to create an audio connection from your browser to Twilio, then tell Twilio to call the other phone number, which will connect the two calls together. This quickstart shows how to use Twilio Client to make an outgoing phone call: http://www.twilio.com/docs/quickstart/csharp/rest

      Hope that helps

  • Mark

    Is there a way to generate a call using a client only, such as the VBS script above? I assume the url = “call-handler-url-here” is something programmed on my website which I would prefer not doing.

    • Devin Rader

      @Mark: Right now there is no client-only solution for making and processing an outbound call that would work in VBS. The way Twilio works is when you tell it to initiate an outbound call, you need to provide a URL that will return the TwiML commands you want to execute when the phone call is answered. This can be generated from your website, or can even be something as simple as an XML file you host on Dropbox or static TwiML hosted on http://www.twimlbin.com.

      Hope that helps.

  • shivali

    hi can i get this code in php

  • Kyle Brown

    It’s very hard finding Twilio documentation on Classic ASP besides this page… but anyways here is an example of how to process an SMS with Twilio and forward it to email (using Gmail and Stunnel), suggests/improvements welcome. In Twilio I have the incoming URL set up as a “HTTP GET” (would a post be just use request.form instead of request.querystring?).

    Got your message

    <%
    Set objMessage=CreateObject("CDO.Message")
    objMessage.Subject="SMS from " & fromsms & " to " & tosms
    objMessage.From="Full Name ”
    objMessage.To=”name@domain.com”
    objMessage.TextBody=bodysms
    objMessage.Configuration.Fields.Item(“http://schemas.microsoft.com/cdo/configuration/sendusing”) = 2
    objMessage.Configuration.Fields.Item(“http://schemas.microsoft.com/cdo/configuration/smtpserver”) = “localhost”
    objMessage.Configuration.Fields.Item(“http://schemas.microsoft.com/cdo/configuration/smtpserverport”) = 25
    ‘Type of authentication, NONE, Basic (Base64 encoded), NTLM

    objMessage.Configuration.Fields.Item _
    (“http://schemas.microsoft.com/cdo/configuration/smtpauthenticate”) = 1
    ‘Your UserID on the SMTP server
    objMessage.Configuration.Fields.Item _
    (“http://schemas.microsoft.com/cdo/configuration/sendusername”) = “name@gmaildomain.com”
    ‘Your password on the SMTP server
    objMessage.Configuration.Fields.Item _
    (“http://schemas.microsoft.com/cdo/configuration/sendpassword”) = “password”
    ‘Use SSL for the connection (False or True)
    objMessage.Configuration.Fields.Item _
    (“http://schemas.microsoft.com/cdo/configuration/smtpusessl”) = False
    objMessage.Configuration.Fields.Update
    objMessage.Send
    set objMessage=nothing
    %>