Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Sending Text Message using Twilio

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 220
    Comment on it

    Here I am sharing sample code for sending Text Message using Twilio dll.


    Twilio provides service to send Text Message, MMs and Voice Messages etc.


    In order to send message using Twilio we first need to install Twilio package from nugget Package Manager. Once we have installed the Twilio package after that we need these four credentials for sending message


    1. Twilio AccountSid
    2. Twilio AuthToken
    3. Twilio Phone Number
    4. Receipient Phone Number


    You will get Twilio AccountSid, Twilio AuthToken and Twilio Phone Number from Twilio application on web when we will login on www.twilio.com/login. Recepient Phone Number will be the number to which you want se send message. It should be prefixed with the country code e.g. +919719XXXXXX.


    Note- If you are sending message from Trial Account then recipient number should be first verified from Twilio web application.


    Once we have all four required fields then we are ready to use code for sending Test Message


     using Twilio; 
    
                public virtual bool SendMessage(string receipientPhoneNumber, string message)
                {
                    try
                    {
                        var twilio = new TwilioRestClient(TwilioAccountSid,TwilioAuthToken);
                        var message = twilio.SendMessage(TwilioFromPhoneNumber, receipientPhoneNumber, message);
                        if (message.RestException != null)
                        {
                            return false;
                        }
    
                        return true;
                    }
                    catch (Exception ex)
                    {
                        return false;
                    }
                }
     

    We are sending the message using TwilioRestClient.SendMessage function. This function will return a message object of Twilio. If the RestException of this object is null, that means message is queued successfully else please read the message.RestException.Message property for error information.


    I hope this will help you when you will send message using Twilio.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: