How we implemented SMS Notifications(HTTP Based SMS Gateway)

Dont create your support topics here! No new topics with questions allowed!

Moderator: crythias

Post Reply
OTRS newbie
Posts: 2
Joined: 19 Dec 2010, 08:30
OTRS Version?: 3.0.4

How we implemented SMS Notifications(HTTP Based SMS Gateway)

Post by timmy_dk » 19 Dec 2010, 09:39

We been using OTRS for some years, but wanted to extend it to also cover our support for business customers.

Since they are very important to us, we receive a SMS with information about the ticket, whenever there is a new one.

Of course when we wanted to use OTRS 3.0.4 for this as well, we need to extend it to also cover SMS Notifications.

I'm been searching around, and the typical suggestions is the use a SMTP based SMS Gateway, supplied by your operator.

First of all not all operators have one, in fact in Denmark, only one provider stil has one.

Second, we still need to receive mail notifications, and the SMS Notifications shouldn't be HTML based.

Since we are a SMS Gateway provider, we wanted to use our own Gateway, which is based on HTTP (We have SMTP aswell), but many providers offer HTTP Support.

So here's the deal.

We wanted to use as many features as possible of those which allready is in OTRS, like "Receive mail on new ticket" etc. we wanted those to be general for both SMS and Mail.

Further more, we wanted to use the email templates for SMS Aswell.

We started by implementing a Mobile number on the agent.

We edited the template for adding and editing agents, here's a diff:

Code: Select all

--- /opt/otrs-3.0.4/Kernel/Output/HTML/Standard/AdminUser.dtl	2010-11-08 23:12:07.000000000 +0100
+++ /opt/otrs/Kernel/Output/HTML/Standard/AdminUser.dtl	2010-12-18 10:16:48.000000000 +0100
@@ -193,6 +193,11 @@
                             <input type="password" name="UserPw" id="UserPw" value="" class="W50pc" maxlength="50"/>
                         <div class="Clear"></div>
+                        <label for="UserMobile">$Text{"Mobile"}:</label>
+                        <div class="Field">
+                            <input type="text" name="UserMobile" id="UserMobile" value="$QData{"UserMobile"}" class="W50pc" maxlength="50"/>
+                        </div>
+                        <div class="Clear"></div>
                         <label class="Mandatory" for="UserEmail"><span class="Marker">*</span> $Text{"Email"}:</label>
                         <div class="Field">
Second, we also need to modify the User model, to be able to update and add mobile number:

Code: Select all

--- /opt/otrs-3.0.4/Kernel/System/	2010-11-30 14:11:11.000000000 +0100
+++ /opt/otrs/Kernel/System/	2010-12-18 10:38:07.000000000 +0100
@@ -400,6 +400,9 @@
     # set email address
     $Self->SetPreferences( UserID => $UserID, Key => 'UserEmail', Value => $Param{UserEmail} );
+    # set mobile
+    $Self->SetPreferences( UserID => $UserID, Key => 'UserMobile', Value => $Param{UserMobile} );
     # delete cache
     my @CacheKeys = (
         'GetUserData::User::' . $Param{UserLogin} . '::0::0',
@@ -495,6 +498,12 @@
         Key    => 'UserEmail',
         Value  => $Param{UserEmail}
+    # set mobile
+    $Self->SetPreferences(
+        UserID => $Param{UserID},
+        Key    => 'UserMobile',
+        Value  => $Param{UserMobile}
+    );
     # delete cache
Last place to edit is the Module:

Code: Select all

--- /opt/otrs-3.0.4/Kernel/Modules/	2010-11-19 23:28:58.000000000 +0100
+++ /opt/otrs/Kernel/Modules/	2010-12-18 10:41:16.000000000 +0100
@@ -149,7 +149,7 @@
         my $Note = '';
         my ( %GetParam, %Errors );
         for my $Parameter (
-            qw(UserID UserTitle UserLogin UserFirstname UserLastname UserEmail UserPw ValidID Search)
+            qw(UserID UserTitle UserLogin UserFirstname UserLastname UserMobile UserEmail UserPw ValidID Search)
             $GetParam{$Parameter} = $Self->{ParamObject}->GetParam( Param => $Parameter ) || '';
@@ -293,7 +293,7 @@
         my $Note = '';
         my ( %GetParam, %Errors );
         for my $Parameter (
-            qw(UserTitle UserLogin UserFirstname UserLastname UserEmail UserPw ValidID Search)
+            qw(UserTitle UserLogin UserFirstname UserLastname UserEmail UserMobile UserPw ValidID Search)
             $GetParam{$Parameter} = $Self->{ParamObject}->GetParam( Param => $Parameter ) || '';
So now we are able to edit, and add a mobile number on an agent.

As the last thing, we need to implement it in the way notifications are sent, keep in mind we want it to work the same way as the email does, so the easiest thing, implement it the same place as an email is sent, so all the check are simular.

We use our own HTTP Bases SMS Gateway, from

As you might notice, we just strip the HTML from the email, and also replace html breaks with line breaks.

Code: Select all

--- /opt/otrs-3.0.4/Kernel/System/Ticket/	2010-12-10 14:03:31.000000000 +0100
+++ /opt/otrs/Kernel/System/Ticket/	2010-12-19 08:33:03.000000000 +0100
@@ -19,6 +19,11 @@
 use Kernel::System::TemplateGenerator;
 use Kernel::System::Notification;
 use Kernel::System::EmailParser;
+# Used for the SMS Gateway implementation
+use LWP::UserAgent;
+use URI::Escape;
+use Encode;
 use vars qw($VERSION);
 $VERSION = qw($Revision: 1.266 $) [1];
@@ -2248,6 +2253,33 @@
         Priority => 'notice',
         Message  => "Sent agent '$Param{Type}' notification to '$User{UserEmail}'.",
+		if($User{UserMobile}){
+    	# Url encode our parameters
+			my $sender = uri_escape("OTRS Ticket");
+			my $username = uri_escape("coolsms_username");
+			my $password = uri_escape("coolsms_password");
+			my $message = $Notification{Body};
+			# Replace HTML <br/>s with line break \n
+			$message =~ s/<br\s+\/+>/\n/g;
+			# Strip all other HTML tags
+			$message =~ s/<(?:[^>'"]*|(['"]).*?\1)*>//gs;
+			# Encode the message in latin1, to ensure it fits with the GSM characters
+			$message = encode("iso-8859-1", $message);
+			# Urlencode the message
+			$message = uri_escape($message);
+			# Generate the URL; and make the HTTP GET
+			my $url = "$sender&username=$username&password=$password&message=$message&to=$User{UserMobile}";
+			my $ua = new LWP::UserAgent;
+			$ua->agent("OTRS");
+			my $req = new HTTP::Request GET => $url;
+			my $res = $ua->request($req);
+			# Log the response, as a notice, for debug purposes
+			$Self->{LogObject}->Log(
+        	Priority => 'notice',
+      	  Message  => "Sent agent '$Param{Type}' notification to '$User{UserMobile}', CoolSMS Response: '$res->content'.",
+    	);
+		}
     # event
I admit it's been a several years, since I last played around with perl, so this might not be the best implementation, and I wish that somebody, will make this even better someday, with configuration options, mobile number validation, and so on.

If anybody is interested in this, we'll be happy to sponsor a SMS Gateway, to do the tests and implementation, in that case please contact me at mnv <at>

I hope that somebody will find this usefull :)

OTRS newbie
Posts: 4
Joined: 15 Dec 2010, 10:44
OTRS Version?: 3.0.4

Re: How we implemented SMS Notifications(HTTP Based SMS Gate

Post by NoBrain » 15 Feb 2011, 16:04


thanks very much. It's very useful.
Only one question: How can I get the Information from: Core::TicketFreeText::TicketFreeKey1?

Cause I'm using the SMS notifications only for high priority tickets and the message for the sms should include "$Notification{Subject}" and the content of Core::TicketFreeText::TicketFreeKey1.



Posts: 266
Joined: 12 Jan 2010, 18:16

Re: How we implemented SMS Notifications(HTTP Based SMS Gate

Post by Mike_B » 17 Feb 2011, 12:40


Thanks for sharing your knowledge.
I'd like to add that it's MUCH simpler to actually store additional information for your agents. We have a powerful Preferences system that you can use for this.

Using the snippet below, you get an extra field for the mobile phone number, which you then can use in the rest of OTRS:

Code: Select all

<?xml version="1.0" encoding="utf-8" ?>
<otrs_config version="1.0">
    <ConfigItem Name="PreferencesGroups###Mobile" Required="0" Valid="1">
        <Description Translatable="1">Defines the mobile phone number of the agent.</Description>
                <Item Key="Module">Kernel::Output::HTML::PreferencesGeneric</Item>
                <Item Key="Column">Other Settings</Item>
                <Item Key="Label" Translatable="1">Mobile phone number</Item>
                <Item Key="Key" Translatable="1">Mobile</Item>
                <Item Key="Block">Input</Item>
                <Item Key="Data">$Env{"UserMobile"}</Item>
                <Item Key="PrefKey">UserMobile</Item>
                <Item Key="Prio">7010</Item>
                <Item Key="Active">1</Item>
Just save this snippet of text as otrs/Kernel/Config/Files/AgentMobile.xml - go to Admin > SysConfig in your OTRS system (this rebuilds the SysConfig), and now you have the extra field in the User Preferences and the Admin screen where you can store the mobile number of your agents.

Mike - @michielbeijen on Twitter

OTRS newbie
Posts: 1
Joined: 28 Sep 2011, 11:01
OTRS Version?: KIX
Real Name: 121312er
Company: 121312er

Re: How we implemented SMS Notifications(HTTP Based SMS Gate

Post by Dominique » 17 Oct 2011, 09:44

I’ve had good luck with Sprint as far as receiving messages sent with this app and knowing what to do when you only send a link.
Not sure it is related to the issues you are running into with Sprint, but there is a conversation going on in the Sprint Developers Forum ( about some changes Sprint may have made in their WAP Gateway and its impact on some WAP sites.
One situation that has surfaced is the way some carriers and devices appear to handle any links that are sent via SMS. In some of the carriers on some of the devices that have been tested so far, URL’s aren’t hot when the user opens the SMS message and need to be cut and pasted into the phones wap browser. It appears to be the minority of cases, but that is something that has popped up.

OTRS newbie
Posts: 10
Joined: 26 Oct 2011, 11:49
OTRS Version?: 3.0.11
Real Name: Jonas Harnesk
Company: StaticAB

Re: How we implemented SMS Notifications(HTTP Based SMS Gate

Post by petfrogg » 18 Jan 2012, 15:21

Since my Perlcoding is limited i ran into trouble with this code and the otrs 3.0.11.

Have anyone rewritten this to a plugin for otrs?
Best regards

CentOS 6.0
OTRS migrating from 2.3.5 to 3.0.11
PS! Dont ticket me for misspelling my name with two "gg"s!


Re: How we implemented SMS Notifications(HTTP Based SMS Gate

Post by Jh0ns0n1 » 19 Mar 2012, 14:02

Can u plz tell me were to add this code as i am still a beginner.....

OTRS newbie
Posts: 1
Joined: 25 Mar 2012, 02:01
OTRS Version?: three
Real Name: Jack Gibson
Company: None - I'm an individual(:
Location: Valencia, Spain

Re: How we implemented SMS Notifications(HTTP Based SMS Gate

Post by JackGibson » 25 Mar 2012, 02:08

Excuse my ignorance, but can this be rolled out accross other countries in Europe? Or will I face problems with the various cell . networks?


“Don't find fault, find a remedy; anybody can complain”
Henry Ford

OTRS newbie
Posts: 1
Joined: 26 Mar 2012, 14:07
OTRS Version?:
Real Name: saurav mawandia

Re: How we implemented SMS Notifications(HTTP Based SMS Gate

Post by saurav_mawandia » 29 Mar 2012, 18:27

i am unable to update the changes.Receiving error security module not enabled.i tried enabling it but the same error came again.Can you help me updating the changes????

OTRS newbie
Posts: 1
Joined: 05 Nov 2012, 10:47
OTRS Version?: 3.0.6
Real Name: Monika Pandey
Company: peogressive Infotech pvt limited

Re: How we implemented SMS Notifications(HTTP Based SMS Gate

Post by Monika » 27 Apr 2013, 08:30

Dear Sir,

I am using OTRS 3.0.6
I have created mobile textbox in agent form .
Please tell me how to implement it with sms notification what other changes i have to make.

Which kind of files will be created and at which location and where SMS gateway setting will be done?
Please help me...very urgent

Post Reply