REQUEST A DEMO

Having Rulemanager send SMS notifications via Twitter

Kevin had an earlier post discussing how Rulemanager could fire a script that would notify all queue members via Twitter when a case is dispatched to a queue. The script took the queue name as an input, queried the database for the queue members, and then sent a direct Twitter message to each queue member.

I liked what he did, and wanted to see if we could take it a step further, and make it more in line with Rulemanager notifications.

Making Twitter a first class Notification method

RuleManager already knows how to resolve queue members into individual users, and it knows how to resolve a notification preference of each user, depending on whether the user is on or off work hours, and also based on the urgency of the message.

Years ago, many people carried digital pagers, which allowed text messages to be sent to their pagers. So Clarify introduced a notification preference of "Digital Pager".  These pagers were typically limited in the amount of text a message could contain. So Clarify created a second message text area for storing a business rule message just for pager messages. Twitter is also limited in its message length – 140 characters is the max.

Twitter and Digital Pagers parallel well, at least in this regard. So we can take over the Digital Pager option, and use that for Twitter notifications. 

Modify the UI to make Twitter an option for notifications

Just a little scripting to replace "Digital Pager" with "Twitter", and now we can set Twitter as a notification option:

 

Setting the Twitter user name

Since we’re taking over the paging capabilities, we’ll simply store a user’s Twitter name in the pager field:

 

Script to send a direct Twitter message

A quick little Javascript that uses curl does the trick here. My script is named notify-twitter-user.js, and here’s its contents:

var arguments = WScript.Arguments;
var argumentsCount = arguments.Count();

if(argumentsCount < 2) {
   WScript.Echo("Usage: notify-twitter-user userName message");
   WScript.Quit();
}

var userName = arguments(0);
var message = arguments(1);

var WshShell = WScript.CreateObject("WScript.Shell");
var userEnv = WshShell.Environment(‘user’);

WshShell.Run(‘curl.exe -u dovetail:XXXXXX -d text="’ + message + ‘" -d user="’ + userName + ‘" http://twitter.com/direct_messages/new.xml’);
WshShell = null;

We’ll call this script like:

cscript notify-twitter-user.js twitterUserName message 

A replacement Paging Application

When RuleManager needs to send out a page, it uses the configured Pager Application. Because this is configurable, we can create our own application/script that does what we want it to do. In this case, we’ll have our pager application turn around and call our notify-twitter-user.js script.

What isn’t configurable is the parameters that RuleManager passes to the Pager Application. But a little debugging yields the details. Rulemanager will call the pager app like this:

pager_clerk.exe -p <pager_type> -t <employees pager number> -m <message to be sent> -e <employees email address>

We want the 4th parameter (the employees pager number), and the 6th parameter (the message to be sent). Then we can call our Javascript script that we created above. I called my new script notify.bat, and here’s its contents:

cscript notify-twitter-user.js %4 %6

In FChoice.RuleManager.WindowsService.exe.config, simply set the PagerApplicationPath variable to our new notify.bat script:

<add key="NotificationConfig.PagerApplicationPath" value="notify.bat" />

If using Clarify Rulemanager, configure the Paging Application setting as per the Clarify Rulemanager documentation. 

Twitter notification preferences

I’ve configured Twitter so that I get an SMS message and an email when a direct message is received.

To get notified of Direct Messages by SMS: In Twitter, click on Settings, then on the Device tab. Add your mobile phone, and set your Device updates to Direct Messages.

To get notified of Direct Messages by email: In Twitter, click on Settings, then on the Notices tab. Check the checkbox that says Email when I receive a new direct message

Create a rule for testing

Object Type: Case
Rule Name/Description: Test rule – notify gary when a note is logged to a case
Start Events: Log Note
Cancel Events: None
Conditions: None
Action Title: Notify 
Who to Notify: gsherman
Start Action: 0 minutes
From: Event Creation
Using: Elapsed Time
Repeat : Never
Message:

RE: Notification for [Object Type] [Object ID]

A note was logged to [Object Type] [Object ID]

[Object Type] Title: [Title]
Severity: [Severity]

Pager Message:

A note was logged to [Object Type] [Object ID]
[Object Type] Title: [Title]
Severity: [Severity]

 

Notice that business rule actions have 2 messages – one for full messages (such as email), and one for short messages (such as pagers). 

Notifications!

Start RuleManager, Open DovetailAgent, Log a note to a case, and lets see what happens. 

Notification by Email:

 

Notification by SMS to my phone:

(sorry for the blurry pic)

 

Notification at Twitter.com:

 

Rulemanager Logs

I can also look at the Rulemanager log file and see exactly what happened:

No calendar found for User login "gsherman", assuming employee is at work.

Notification preference for User login "gsherman" and severity "Medium" determined to be "DigitalPagerNotification".

User login "gsherman" was added to the Pager Notification (DigitalPagerNotification).

Starting process: ""notify.bat"" with arguments "-p DIGITAL -t "gsherman" -m "A note was logged to Case 16  Case Title: new employee case Severity: Medium" -e "gsherman@fchoice.com"" in directory "C:Program FilesDovetail SoftwareRule Manager&quo
t;
 

And there you have it – Rulemanager sending SMS notifications via Twitter.

Rock on.