im_atrey
Tera Contributor

Most conversations will end up taking place on WhatsApp, be it a simple greeting, gossip, news, or networking. The very first thing that comes up in our mind is WhatsApp. Almost every industry leverages it or heading towards using it in growing its business and improves its reach to its customers.

How about ServiceNow to leverage WhatsApp?


This #know20 another interesting topic came up, Welcome to another article, ServiceNow integration with "WhatsApp".

 

Whenever do you want to perform integration what is the first thing that comes in your mind?

find_real_file.png


Yes, we need to know whether API is Open-source or Paid. If API is open-source then will check for its developer account, documentation, and sample message but what if API is paid then the first thing we ask Is there any tool or interface which can be leveraged to integrate?
 
WhatsApp
does have APIs but those are business APIs, which requires a paid subscription.

Now, we know WhatsApp APIs are not open source then must require some interface or tool, using that we can integrate ServiceNow to access the WhatsApp APIs.

One of the interfaces is Twilio, it also provides the interface to integrate with WhatsApp APIs, and there are other features that it offers like make calls, send SMS, etc so on. Now we have to integrate ServiceNow with Twilio to enable the WhatsApp integration.

That's great !! but what next?

  • Do I need to perform double integration?

  • Whether Twilio APIs are paid or open-source.

  • Does it have proper documentation for that?

  • In ServiceNow, what are prerequisites to set up this integration?

  • Is there any additional plugin or spoke required?

Those might be the questions that come in mind. Right?

Let's discuss the prerequisites for Twilio and ServiceNow one by one. 

  • Twilio prerequisites:-

  • You need a Twilio developer account.

  • Goto communication cloud selects Programmable SMS.

find_real_file.png

(a) Selecting Programmable SMS


  • Select WhatsApp beta in Programmable SMS.

find_real_file.png

(b) Use code to connect WhatsApp 

find_real_file.png

(C) Sending code to+14155238886


  • Sandbox is now ready but some important things are required from Twilio, which are as follows:
  • As we have to make POST requests, endpoints should be like 'https://api.twilio.com/2010-04-01/Accounts/<account id>/Messages.json'.

  • Username: Account ID and Password: Auth Token.
  • From(phone number) which Twilio provides.

find_real_file.png

 (d) Endpoints, header, Username and To and From

 

So far, we have collected the prerequisites from Twilio, but before we jump to setting up it in ServiceNow, we need to understand its flow. How requests trigger from ServiceNow to Twilio and how Twilio triggers WhatsApp message to "To"(dedicated WhatsApp number). 

find_real_file.png

(e) Request ServiceNow to WhatsApp

 

Instead of using the conventional outbound setup within ServiceNow, this time we will use Flow Designer with IntegrationHub, we simply need to define a flow to automate the process in ServiceNow along with action which is responsible for Rest Call to Twilio.

  • Architectural Overview

find_real_file.png

(f) Architectural view-flow and IntegartionHub 

 

  • Two main components at ServiceNow is Flow and IntegrationHub, by leveraging these two stacks we communicate from ServiceNow to WhatsApp.

  • Flows: It enables business process analysts to automate approvals, tasks, etc without using code/script. There are 3 components to design flow Trigger, Action, and Flow-Logic.

  • Trigger:- How do you want to initiate the flow. The trigger can be of schedule type or on the basis of record being created/updated.

  • Action:- It allows automating the process, basically, these are the sequence of steps the flow follows. Action can be used to create the task, ask for approvals, or automate flow with 3rd party applications, etc and so on.

  • Flow-Logic:- How flow leverages conditions to move forward. These can be conditional logic like If-Else, Do it in parallel, For-Each, etc.

  • IntegrationHub: It enables the execution of third-party APIs as a part of a flow when a specific event occurs in ServiceNow. It is next-gen. Integration and Orchestration solution which extends digital workflow to any external platform.

  • The integration that is built using hub is called Spokes.

  • Spokes are easy to configure and enable you to quickly add powerful actions without the need to write a script.

  • You can leverage XML parser, payload builder, PowerShell, and SSH commands without the need to write script/code.

find_real_file.png
(g) Functions within Action. 

 

 

  • Design Action in ServiceNow to get connected to Twilio, below are the steps:-

  • Goto Designer in Flow-Designer and selects New and choose 'Action' tab.

find_real_file.png

(h) Action in flow-designer.


  • Once you fill the name, category, and description, then Action designer window comes up.

find_real_file.png

(i) Action-Designer pane.

 

  • Now you are in action-designer, let's define inputs, WhatsApp integration requires 3 inputs (i) From (Official WhatsApp no.) (ii) To (User's WhatsApp no.) and (iii) Body (Message body).

  • In this scenario From =+14155238886, Twilio has its own format for defining mobile no. it should be like <+country code><mobile number>.

  • To also should be in the same format.<+country code><mobile number>, eg. for India country code is +91 and mobile no. is 9XXX2113XX, then To = +919XXX2113XX.

  • Body contains the message that you want to send to "To" from "From".

find_real_file.png
(j) Inputs in Action-Designer.

 

  • Type for 'From' and 'To' should be Phone Number or Phone Number(E164).

  • Apart from 'From', 'To' and 'Body', let's define another 4 input, which has to use as a prefix when you will make REST call to Twilio. Twilio accepts its own defined format and that should be in encoded format.

  • In this step, you will use the Script step to parse the To and From mobile number to remove any special characters because Twilio API accepts the mobile number without special characters, eg. From +1(408) 555-0004 to +14085550004.

  • Along with parsing, we will encode the prefix, so that it can be leveraged to make a REST call to Twilio with correct format.

find_real_file.png

(k) script-step to remove a special character.

As of now we remove the special character from numbers and encode the prefix. For the REST step to be executed correctly, we must need connection and credentials. Don't scratch your head on credential and connection.

  • Connections encompass Endpoint URL, credentials, domain, and alias.

find_real_file.png

(l) Connection and Credential alias.

  • Credential holds Authentication Type, WhatsApp integration uses Basic type so, for it, the username is <Account ID> and password is <Auth Token>.

Now, we have configured the connection and credentials, so let's move back to Action and define the REST step for this integration. Again in step panel, select the and choose the REST in the action window.

In the REST step, fill connection details, request details, and request content, etc.

  • Connection details encompass of connection, connection alias, and base URL.

find_real_file.png
(m) REST step in action designer.

Note:- Base URL will populate automatically if you choose connection as 'Use Connection Alias' and connection alias as specific to your integration.

  • Request details contain build requests, resource paths, and so on.

  • Request content encompasses request-type and inputs on the basis of request-type.WhatsApp requires "Form URL-encoded" as a request-type, and its inputs are From, To, and Body that we have defined in the above step.


find_real_file.png
(n) Request content in the REST step.

 

  • Let's quickly recap what has been done so far, we defined inputs, the script has been written to remove special character from phone nos. and convert "whatsapp:+"  to whatsapp%3A%2B which is uri-encoded format.


Now, we have configured most of the steps but What do you think thats it? Is integration completed?

No, Integration is incomplete without "Error - Handling" capability. Error handling makes integration robust as it helps to understand the error on basis of status code and error message,so that you can build fault-tolerant actions that can be recovered through Flow Logic or through analyst interventions. Include error handling to allow flows to fail gracefully and provide valuable troubleshooting details when errors are encountered.

 

  • Create another script step that can be leveraged to handle the errors, and within script steps you can invoke resusable classess, what we call Script-Includes. 

find_real_file.png

(o) Error-handling step.

 

 

All the steps is completed, the response that we receive from Twilio, it has to be available to flow and to do this we need to to define Action outputs as last step in this integration so that we can leverage the response to design conditional flow or can perform further configuration.

  • Action Outputs:- It returns response or data from action to flow-designer, script-steps you define are only available to action itsself and to leverage it in flow-designer Action-Outputs are required.

find_real_file.png
(p) Action-outputs.

Custom spoke or action is completed,Now, test your action and validate the results.To validate the results flow-designer execution tab is best as it encompasses information about triggers,actions,outputs wether your step gets passed or failed.

 

  • Test requires 3 inputs, what we have defined in initial step those are From, To and Body.

find_real_file.png
(q) Test Action.

WhatsApp integration with ServiceNow is done, it totally up to you or on to business requirement How do you want to leverage this custom spoke or custom action?

I have designed the whole application which is leveraging this custom spoke and on creation of incident I am sending details to Caller of the incident. If you want to leverage that application and get your hands dirty you can fork in your Git from https://github.com/aatrey882/ServiceNow-Twillio-Whatsapp.

As this is custom spoke you should have Git account and after then you can fork from above repository. First time you need to import it manually in your instance.

The application I created has following components :-

  1. WhasApp-Twilio Flow - Flow that is being used to automate the process.

  2. WhatsApp-Twillio - Action that helps to get connected to WhatsApp API.

Other customization are in incident form, there I have created section called WhatsApp Section. You dont need to create that section, once, you import the application it gets installed automatically.

find_real_file.png
(r) Form section on incident.


In application you will find two tables (i) WhatsApp Configuration and (ii) WhatsApp Transaction logs, before you start building over those just go through from their schema and learn about How they are connected to each other? and How those can be leveraged in other tables to enable this Integration?

Top takeaways :-

  • Action-designer allows you to create custom spoke through which you can make it dynamic.

  • Leverage flow is better way to automate the process without need to write code/script.

Cons of Twilio API :-

  • To setup inbound you must have subscription for their upgraded version.

  • No dedicated inbound for WhatsApp in twilio,either you have to use TwiMl or Conversation API.

  • If you want to customize the WhatsApp then you should have approval form WhatsApp business.

 

I hope this integration helps you to know How to leverage WhatsApp in ServiceNow.I believe you will build over this application and design some cool offering.

Mark it helpful if you like this article and find it informative and also subscribe to it.

Happy Learning !! Stay Safe!!

Regards 

Aashish Atrey

 

 

 

Comments
chirag_bagdai
ServiceNow Employee
ServiceNow Employee

Nice article Aashish 👍 We are happy to see how you  leverage the CreatorCon Session.

I would like to add few reference links here for those who are interested to attend CreatorCon session on how to build WhatsApp Spoke.

Course in NowLearning:

https://nowlearning.service-now.com/lxp?id=overview&sys_id=54b6a4c31bb4d4901759b8c11a4bcb3f&type=cou...

Lab Guide:

https://developer.servicenow.com/connect.do#!/event/knowledge2020/CCW2886

And the community post for Q&A:

https://community.servicenow.com/community?id=community_question&sys_id=80f7db90db2018104819fb243996...

Vivek Verma
Mega Sage
Mega Sage

Hi,

This is one the best article in community.

I have one query here, Is it possible to implement this integration using legacy Rest Message Method.

If Affirmative, Then How can I send the Request type -- Form URL-encoded rest message method.

 

Thanks,

Vivek|LinkedIn

stb2
Kilo Contributor

Congrats to the technical Part here amazing JOB! 

BUT:

DO you really want to share sensitive company Data over WHATS APP???

 

I mean think about it.... How much more Data should Mr. Zuckerberg get for free, from us ?

And now even company data where u discuss users/logins/keys and a ton of other security stuff?

 

Security Concerns anybody? 

 

Can you use the same thing for Signal e.g.?

im_atrey
Tera Contributor

Hi Vivek,

Thanks. Yeah you can configure using traditional REST Message.

So, in HTTP method in REST message you need to pass header content-type: application/x-www-form-urlencoded.

 

 

Mark it helpful if you like this article and find it informative and also subscribe to it.

Regards

Aashish Atrey

im_atrey
Tera Contributor

Hi Stb,

I Agree company sensitive data should not be shared via Whats-App.

This functionality can be leveraged to notify end user or to provide information for your Submitted Orders state or Incident state.

Yes, I found some security concerns but those can be over come if you use WhatsApp APIs, but again you must satisfy WhatsApp t&c to get those APIs and get your business registered with Facebook as WhatsApp API is managed by Facebook.

 

 

Mark it helpful if you like this article and find it informative and also subscribe to it.

Regards

Aashish Atrey

Prasanna Kuma12
Tera Contributor

Can you please provide documents to integrate Vonage API to Service now SMS. Please help on the same.

 

Thanks & Regards,

Prasanna Kumar

pranav12
Giga Contributor

How do i Get Whatsapp credential?

Megatron1
Tera Contributor

Thank you for the clear set of instructions and information. The question that i have is

1. Can an incident be created in ServiceNow from a message in whats app through twilio?

Can this be achieved via Conversation API?

2. Can we set broadcast messages from WhatsApp in ServiceNow ?

3. Can attachments be shared from either ServiceNow to WhatsApp or vice versa

im_atrey
Tera Contributor

Response Inline:-

  1. Yes, incident can be created but I would suggest to go via WhatsApp direct API instead of Twilio API
  2. Yes, you can set the broadcast message.
  3. Not with Twilio API.

 

Kindly mark helpful if you've got your answers.

Nithin15
Tera Expert

Thank you for sharing. 

Are these resources moved to different location ? 

When I click on link, it says resource not found

Anandhi Benita
Tera Contributor

Hi @im_atrey 

Thank You for the Clear explanation.

 

I have one question regarding this.

Can we try using Twilio trial account, If Yes I can't able to see the screen which I've attached below

 

AnandhiBenita_0-1672896127744.png

Kindly help me to solve this.

 

Thanks in Advance

Pablo33
Giga Explorer

Nice article, do you know if there is some communication with the Virtual agent? in ServiceNow, let me tell you why, there is a customer who need to integrate Whatsapp and Teams apps but hey just have CSM std, so the account executives said they need to buy the pro version because the virtual agent is on that version but you did not mention anything in your article, so it means they can do it just with the Flow and the IntegratioHub?

 

thanks in advanced

Best Regards 

Pablo 

akshayaarma
Tera Contributor

Hi @Anandhi Benita  

 

were you able to implement the integration using the Twilio trial account?

 

 

Regards,

Akshay Sagar

Version history
Last update:
‎06-06-2020 09:07 AM
Updated by: