The SMS Service allows the K2 Server to send SMS messages and to also receive text messages. The service also allows for K2 to act upon the content received in the message from simply storing the message, starting a specific workflow by texting a specific hash tag and lastly being able to action a task by sms message.
See it in Action
For this service to work correctly you need to have a subscription to Esendex sms service (www.esendex.com) . You can register for a trial account to start off with. They will give you some sms messaging credits and a mobile number. You will need to make a note of the following information.
- Account Number
- Mobile Number
The zip file contains the following components
- SQL scripts to create the database
- GUID for SQL db. Service Object
- Package and Deploy file for the K2 Artefacts
- SMS Receiver
- SMS endpoint assembly
- Code Solution for items 4 & 5
The following steps go through the process of setting up the K2 server with the SMS Service.
- Register for an account at Esendex.com
- Run the sql scripts. This will create the K2 SMS database
- The next step is to register the database with K2. When registering the database with K2 make sure the ‘Authentication Mode’ is set to ‘Service Account’ and the service is called ‘K2 SMS’ and it has this guid ‘1be32a72-9693-4f4a-a143-99adea6e850d’
- Once the service object has been created. You will then see all the stored procedures and tables that make up the K2 SMS database. It Should look something like this
- The next service to register is a endpoint assembly that allows the K2 SMS Service to action tasks. In the zip file there is a .dll called ‘K2Core.dll’. Register this as a endpoint assembly with the name ‘K2 Core Tools’ and with the following guid ‘dab558bf-99ca-4a4f-80d7-865032849d5’ This will then create the following service objects for you.
- The last service to install is another endpoint assembly that allows K2 to send sms messaging. Open up the solution ‘K2SMS’ and edit the project ‘K2SMS’ and edit the following files ‘Receive.cs’ and ‘SendTxt.cs’ and replace the following details with your Esendex details
private static string _Username = “Esendex Username”;
private static string _Password = “Password”;
private static string _Account = “Account”;
Once you have done this build the project and then register the created dll as a endpoint assembly. Call the endpoint ‘K2 SMS’ and make sure it has the following guid ‘08700ee5-116f-4894-b921-1fd593e93554C’ It will then create the following the service objects
- Now that all the service objects have been created. You can now deploy the K2 package called ‘K2 SMS.kspx’ This will deploy the following K2 Artefacts for you
- Now that the package has been deployed you are now able to test the service by sending an sms message. Use the smartobject tester and execute the ‘Send SMS’ smartobject. Enter in a mobile number and the message. You should then receive the message on your mobile phone and if you execute the ‘GetInbox’ smart object. You will be able to see the message in the list.
- The next step is to add the web api handler that Esendex will post it’s responses too. In the zip file copy the folder ‘sms’ on to the c drive
- Open up IIS and expand ‘K2’. Right click and select ‘Add Application’
- Enter ‘K2SMS’ in the Alias and select ‘K2 Smarforms’ as the application pool and then browse to the ‘sms’ folder you copied over. It should look something like this
- On the newly created application, click on ‘Authentication’ and enable ‘Anonymous Authentication’. Your handler is now ready to receive posts from Esendex. We now just need to tell esendex where to post the messages too.
- The url for your service will be the following
If you go to that URL now you should get a xml document error, don’t worry that is fine it’s just expecting to get a xml document.
- Login into your esendex account and go to ‘Developer tools’ and in the ‘Configure Push Notifications’ section click on ‘configure’ for ‘SMS received’ and enter in the url of your sms handler.
- You are now ready to test the service. Reply back to the message you sent in step 8. If there is an error you will be sent an email to the account that was used to register the service.
- Go back to your smartobject tester and execute the ‘Messages’ smartobject. You should see the message you have just sent in the list. If you do the setup has been successful and K2 has picked up the message and saved it into sql and the server is now ready to use the service.
Now that the service has been installed you are now able to able to send and receive text messages. I have split the next section into a number of use cases
- To Send a message you can use the following smart object ‘Send SMS’ this allows you to send messages to any mobile number. It has the following parameters ‘Message’ and ‘Mobile Number’
- To be able to get a list of messages received you can use the ‘Messages’ smartobject this will show you a list of messages that K2 has picked up.
To be able to start a workflow from a sms message. The service uses #hashtags to identify which process to start.
- The first thing to do is to register the workflow that wants to be started by a sms. Using the following smartobject ‘SMSHashtagLibrary’ You will need to provide the following information
- Full Process Name
- App definition Id (App Framework)
- The process being called will also need to have some data fields added these are as follows
- AppDefinitionId (Integer)
- AppId (Integer)
- MessageId (Integer)
If the sms message contains more text after the hashtag it will try and connect it to an existing App Instance by matching the ‘App Instance folio’ to the additional text.
For example, if you sent the following message ‘#Help A0011’. The service would start the workflow linked to ‘#Help’ and then try and find the correct record where the folio in the smartobject ‘CM App’ matches ‘A011’
- You will also need to give the process that has been setup to start via sms permissions to be started via ‘ K2WebService’ account.
- Once you have done steps 1 to 3 you are now able to test the service. You can check to see if this has worked by looking in the ‘K2 workspace reporting’ to see if an instance of your sms enabled process has started.
Using the service to send tasks and actions via SMS
To be able to send a task and action a task via sms there is no special wizards it’s just a couple of smartobjects that need to called.
Send a Task
To send a task via SMS you will need to use the following smart object ‘SMSTasks’
The properties you need to populate are the following
- MessageId (If applicable)
- Mobile (Should be the mobile number of the destination user)
Once these details have been created, the SMS service will now monitor the incoming messages for the serial number . Please note you will still need to create your normal client event with the destination user as a ‘K2 Web Service’
The next smart object to use is the ‘Send SMS’. For the mobile number make sure it’s the same one used to record the task and that the message body contains the serial number and what the actions are.
Action a task via sms
To action a task via SMS, the user who received the text message will need to reply back to the message. The message will need to contain the serial number and the action. For example it would look like this ‘12_1222 Yes’
K2 will then pick up the message, it will first of all check to see if the serial number is valid for sms task actions. If it is it will then check to see if the mobile number the message was sent from is the same number the task was initially sent to. If it is all valid it will then try to execute the task based on the action that was included in the message.
You can download the source code from GitHub https://github.com/SimonAllport/K2-SMS
K2 Artefacts and SQL shttp://1drv.ms/1C9KpUpcripts can be downloaded from here
This project is completely open source and is not supported by K2