Please wait
Talk to Expert
Microsoft Dynamics Business central

Optimizing Customer Engagement through SMS Integration

Feature Image-SMS Integration with Business Central

Integrating SMS functionality with Microsoft Dynamics 365 Business Central can significantly enhance business operations by enabling real-time communication, improving customer engagement, streamlining processes, and enhancing service delivery.

Here are the key Purposes and Benefits of such integration:

  • Improving customer communication by sending real-time alerts and notifications to customers about order statuses, delivery updates, appointment reminders, and more. This keeps customers informed and reduces uncertainty.
  • Using SMS for marketing campaigns, promotions, and personalized offers. SMS messages have higher open and response rates as compared to emails, leading to better customer engagement.
  • Set up automated SMS reminders for due payments, invoice due dates, service renewals, and appointment confirmations, reducing missed payments and appointments.
  • This helps maintain optimal inventory levels and reduces stockouts by notifying staff about low levels of stocks or inventory dispensaries.

There are many 3rd party SMS service providers available in the market that offer APIs for integration like

  • Twilio
  • Nexmo (Vonage)
  • Plivo
  • ClickSend

Here in this blog SMS integration will be done by using Twilio service provider.

Integrating Twilio with Microsoft Dynamics 365 Business Central enables your application to send SMS messages, make phone calls, and use other communication services offered by Twilio. Here’s a detailed step-by-step guide on how to set up this integration using AL (Application Language) in Business Central.

  1. We need a Twilio Account. For that, we must sign up at Twilio.
    Twilio Sign-up Page
  2. After following the steps, we get the Account ID and Auth Token. Store it in at secure place for further use for authentication of our API.
  3. Now next step is to get our verified Twilio Phone number from which we send SMS to all.
    Twilio Account Setup page
  4. Now create a Messaging Service for sending bulk SMS.
    Message Service setting up
  5. After the below-shown steps, we can create our Messaging Service.
    Messaging Service Setup
  6. After creating a Messaging Service, we will get one unique ID called Service ID (SID). Store it in a secure place. We will use it in API.
    Messaging Service
  7. Now we will create a new code unit and create an AL procedure for sending SMS through HTTP services.
  8. For sending SMS, we have to use POST method.
    procedure SendSMSUsingMessageService(MessagingServiceSid: Text[100]; ToPhoneNumber: Text[20]; MessageBody: Text)
    var
    HContent: HttpContent;
    HContent1: HttpContent;
    H_Headers: HttpHeaders;
    H_Headers_: HttpHeaders;
    HClient: HttpClient;
    ResponseMessage: HttpResponseMessage;
    HttpRequestMsg: HttpRequestMessage;
    url: Text;
    TextResponse: Text;
    Data: Text;
    TypeHelper: Codeunit “Type Helper”;
    TwilioPhoneNumber: Text[20];
    SMSBody: Text;
    begin
    AccountID := ‘your Account ID;//created in first step
    AuthToken := ‘your Auth Token’;
    TwilioPhoneNumber := ‘Your Twilio No.;// created in third step
    Clear(url);
    Clear(Data);
    url := ‘https://api.twilio.com/2010-04-01/Accounts/’ + AccountID + ‘/Messages’;
    HContent.Clear();
    HClient.Clear();
    H_Headers.Clear();Data := ‘To=’ + TypeHelper.UrlEncode(ToPhoneNumber) + ‘&MessagingServiceSid=’ + TypeHelper.UrlEncode(MessagingServiceSid) + ‘&Body=’ + TypeHelper.UrlEncode(MessageBody);
    HContent.WriteFrom(Data);
    HContent.GetHeaders(H_Headers);
    HClient.Post(url, HContent1, ResponseMessage);
    if H_Headers.Contains(‘Content-Type’) then
    H_Headers.Remove(‘Content-Type’);
    H_Headers.Add(‘Content-Type’, ‘application/x-www-form-urlencoded’);
    HClient.DefaultRequestHeaders.Add(‘Authorization’, ‘Basic ‘ + Base64ConvMgt.ToBase64(AccountID + ‘:’ + AuthToken));
    HttpRequestMsg.Content(HContent);
    HttpRequestMsg.SetRequestUri(url);
    HttpRequestMsg.Method(‘POST’);
    if HClient.Send(HttpRequestMsg, ResponseMessage) then begin
    if not ResponseMessage.IsSuccessStatusCode then begin
    if ResponseMessage.Content.ReadAs(TextResponse) then
    Message(‘HTTP error response %1’, TextResponse);
    end
    else
    begin
    if ResponseMessage.Content.ReadAs(TextResponse) then begin
    if TextResponse.Contains(‘<faultcode>’) then
    Message(‘HTTP error response %1’, TextResponse);
    end;
    if ResponseMessage.IsSuccessStatusCode = true then
    Message(‘SMS sent successfully’);
    end;
    end
    else
    Error(‘Failed’);
    end;
  9. For example we want to send details of posted sales invoice to the customer. For this, an action is created on the Posted Sales Invoice page  and above created procedure is called from the action for sending details of the Invoice to the customer.

    action(SendSMS)

    {
    ApplicationArea = all;
    Caption = ‘Send SMS’;
    Promoted = true;
    PromotedCategory = Process;
    trigger OnAction()
    var
    SMSIntegration: Codeunit “SMS Integration”;
    cust: Record Customer;
    MessageBody: Text;
    begin
    Rec.CalcFields(“Amount Including VAT”);
    MessageBody := StrSubstNo(‘Invoice No: %1, Total Amount: %2, Customer No & Name: %3 – %4’, Rec.”No.”, Rec.”Amount Including VAT”, Rec.”Sell-to Customer No.”, Rec.”Sell-to Customer Name”);
    if cust.get(Rec.”Sell-to Customer No.”) then
    SMSIntegration.SendSMSUsingMessageService(‘your_messaging_serviceID’, cust.”Mobile Phone No.”, MessageBody);
    end;
    }
  10. Output of SMS:
  11. We can also track logs of sent messages from the Twilio portal as shown in the below snip.

If you’re curious about how we can assist you in reaching your goals, don’t hesitate to get in touch. Our dedicated team is ready to provide support every step of the way.

Let’s turn your vision into reality together!


Comments