RSS

How to Send Text Messages from Dynamics AX Using Twilio

26 Aug

Have you ever wished you could send text messages from Microsoft Dynamics AX? Because text messages are nearly always read, they are an ideal way to communicate alerts or reminders for employees, suppliers or end customers. I recently had a client who wanted to send text messages from AX, so I looked at several AX-to-SMS solutions. They were all far too complicated, so I decided to create something much simpler.

Texting from Twilio

I found an easy way to create my own SMS / text message solution using Twilio. You need some software development expertise, but it’s actually pretty easy to setup.

Let’s walk through the process of setting a free Twilio account, buying a local phone number (from which you will send for test message), installing Twilio API using NuGet and implementing API using your newly created Twilio credentials.

Setup a Twilio account

  1. The first steps is to create a Twilio account.
    Twilio Sign Up
  2. Log in and create a number. It is FREE to create a number.
  3. Click on “Buy a number” and choose any number you want.
    Twilio Buy Number
  4. Go to your “Account Settings”, make sure to copy “AccountSID” and “AuthToken.”
    Twilio Account Settings

Visual Studio

  1. Create a VS Project.
    Adding a VS Project
    Class Library
  2. Install Twlio API using NuGet.Installing the Twilio API
  3. Install-package Twilio.
    Twilio Install Package
  4. Twilio API will be added to the project.
    Twilio API will be added
  5. Create your first .NET app.using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Twilio;namespace Twilio
    {

    public class AXTwilio
    {

    public AXTwilio()
    { }

    public string sendAxSMS(string _to, string _message)
    {

    // Find your Account Sid and Auth Token at twilio.com/user/account

    string AccountSid = “your Twilio account SID”;
    string AuthToken = “your Twilio Authtoken”;
    var twilio = new TwilioRestClient(AccountSid, AuthToken);
    var message = twilio.SendMessage(“+18172032952″, _to, _message);
    return message.Sid;

         }

      }

    }

     

  6. Right click the project, “Add Twilio to AOT” and then “Deploy.”
    Add Twilio to AOT

In Microsoft Dynamics AX

  1. Verify Twilio project in AOT (Visual Studio Projects > Dynamics AX Model Projects > C Sharp Projects).
    Verify Twilio Project in AOT
  2. Create a simple class like below and run it.public static void main(Args _args)
    {

    System.Exception ex;

    Twilio.AXTwilio twilio = new Twilio.AXTwilio();
    System.String to = “1112223333”;
    System.String message = “Hello from AX World”;

    try
    {

    twilio.sendAxSMS(to, message);
    info(“Messge Sent”);

    }
    catch(Exception::CLRError)
    {

    ex = ClrInterop::getLastException();
    if (ex != null)
    {

    ex = ex.get_InnerException();
    if (ex != null)
    {

    error(ex.ToString());

    }

          }

    }

        }

     

  3. Message is sent to my number like below.
    Twilio SMS confirmation

Conclusion

The business applications of using SMS with Twilio in AX is endless. With this solution, you can contact your customers, vendors, employees directly from within AX. You can create an SMS alert on each step (confirmation, picking, packing, invoice) of sales order process. You can send ETA alerts with arrival estimates and arrival confirmations, directly integrated with an existing GPS, field service, and order tracking systems. You can use automated SMS to coordinate with the field from your existing service management system and increase precision.

Download our whitepaper and learn why CFO’s throughout the world choose Microsoft Dynamics AX and mcaConnect!
Advertisements
 
3 Comments

Posted by on August 26, 2015 in Development

 

Tags: , , , , , , , , , , , ,

3 responses to “How to Send Text Messages from Dynamics AX Using Twilio

  1. Jorge Bobadilla Gromthorns

    February 11, 2016 at 9:39 pm

    Excellent , but i got a problem with the APi reference , The AOT is not being aknowlegde the API .
    I installed with nuget APP and in the property copylocal is (Yes) on VS

    MSB3245: Could not resolve this reference. Could not locate the assembly “Twilio.Api”. Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.

    I will appreciate if you can give a hand on this ,Thank you!!

     
    • Hai Nguyen

      February 11, 2016 at 9:46 pm

      Make sure you dropp the dll file to server bin folder. You might need to drop to client bin folder as well. After copying the file to server bin folder, you need to restart AOS so that i can pick up the new dll file.

       
      • Jorge Bobadilla Gromthorns

        February 15, 2016 at 4:28 pm

        Very apprecciate for your Response !!, i think one of the limitants to working with references in Ax is the third party unsigned ones , so in many tries i just ended signind the Twilio Nuget dlls and uploading with gacutil to the server… i know is not a good solution but finally is working
        .

         

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: