Difference between revisions of "Callback over Email"

From Kolmisoft Wiki
Jump to navigationJump to search
 
(7 intermediate revisions by 2 users not shown)
Line 1: Line 1:
=About=
[[Callback|Callback Addon]] is needed in order to use email/sms callback.
<br><br>
= Description =
= Description =


Line 35: Line 39:
=== NOTE: email format should be plain, not html!===
=== NOTE: email format should be plain, not html!===


<br><br>
= SMS Gateway example =
[[File:sms_gateway.png|500px]]<br>
http://www.sms-gateways.co.uk/sms-gateway-pricing.shtml


<br><br>
<br><br>
Line 59: Line 69:
2. Postfix server gets email and sends to /usr/local/mor/mor_email2callback.sh script
2. Postfix server gets email and sends to /usr/local/mor/mor_email2callback.sh script


'''''(This step is already configured for you)'''''
'''''(It is already configured for you)'''''


This is configured in /etc/aliases file:
This is configured in /etc/aliases file:
Line 67: Line 77:


3. /usr/local/mor/mor_email2callback.sh script parses email and sends everything to MOR.
3. /usr/local/mor/mor_email2callback.sh script parses email and sends everything to MOR.
'''''(It is already configured for you)'''''


  <nowiki>wget -o /dev/null -O /dev/null "http://localhost/billing/emails/email_callback?subject=$subject&param1=$param1&param2=$param2&param3=$param3"</nowiki>
  <nowiki>wget -o /dev/null -O /dev/null "http://localhost/billing/emails/email_callback?subject=$subject&param1=$param1&param2=$param2&param3=$param3"</nowiki>
Line 73: Line 85:




<br><br>
=Email Callback Setup example=
In order Email Callback would work <u>you must</u>:
* Have a working Device in MOR
* Have a [[CLIs_(Incoming_CallerIDs)|CLI]]  set for that device with '''Use for Email Callback''' option selected
* Point your domain MX record to MOR system (required when you go to Production). During this example we will send an email from the MOR system itself so MX record setup is not needed to test this feature.
<br><br>
==Step 1. Configure MOR==
1. Create a new sip device for a user. In this example created new device has an extension 1003. We will use this extension number as '''Source''' phone number in this callback example.
2. Create a new CLI for that device
1) Go to device list: '''SETTINGS -> Users -> Devices'''
2) Click the [[File:Icon_clis.png]] button on the device you have just created.
3) Create a new CLI as described [[CLIs_(Incoming_CallerIDs)|here]], when creating be sure to select '''Use for Email Callback'''
<br><br>
==Step 2. Test Email Callback from MOR system itself==
For testing we will use Linux utility called mail. To make sure it is installed run this command:
yum -y install mailx
1. Go to MOR system's console (shell) and run this command:
mail -s callback callback@localhost 
'''P.S. when you will go to production @localhost will be @your_domain.com and email can be sent from any email client.'''
<br><br>
2. After launching command mentioned in 1. enter this text as email body:
MOR_PARAM1 1003
MOR_PARAM2 1003
MOR_PARAM3 1004
'''Explanation:'''
MOR_PARAM1 1003 - '''1003''' here is a CLI you have configured in '''Step 1.''' when configured MOR
MOR_PARAM2 1003 - source device where callback should call first
MOR_PARAM3 1004 - destination where callback should call to. Can be any valid phone number, for example 37067531060 or extension in MOR. In this example we used an extension 1003 in MOR.
<br><br>
3. Press CTRL+D to finally send an email.
If you will be asked any questions, just press enter.
4. Now you should receive the call.
<br><br>
==Troubleshooting==
===Check if email reaches the server===
1. In console execute this command:
tail -f /var/log/maillog
2. Now send the email to the system
3. If you get something similar:
Aug 19 10:50:13 localhost postfix/pickup[8237]: 84E4D3E0475: uid=0 from=<root>
Aug 19 10:50:13 localhost postfix/cleanup[9095]: 84E4D3E0475: message-id=<20110819075013.84E4D3E0475@localhost.localdomain>
Aug 19 10:50:13 localhost postfix/qmgr[2821]: 84E4D3E0475: from=<root@localhost.localdomain>, size=381, nrcpt=1 (queue active)
Aug 19 10:50:13 localhost postfix/local[9097]: 84E4D3E0475: to=<callback@localhost.localdomain>, orig_to=<callback@localhost>, relay=local,
delay=0.21, delays=0.04/0/0/0.16, dsn=2.0.0, status=sent ('''delivered to command: /usr/local/mor/mor_email2callback.sh''')
Aug 19 10:50:13 localhost postfix/qmgr[2821]: 84E4D3E0475: removed
Aug 19 11:25:42 localhost postfix/qmgr[2821]: D86A63E0471: from=<root@localhost.localdomain>, size=367, nrcpt=1 (queue active)
that means that email was successfully received in MOR system and arguments were passed to a callback script.
<br><br>
If you '''cannot see any log output''' when email is sent to server, make sure that Postix is running and listening on Public IP or all IPs:
# netstat -vatupn | grep 25
tcp        0      0 '''127.0.0.1:25'''                0.0.0.0:*                  LISTEN      1458/master       
tcp        0      0 ::1:25                      :::*                        LISTEN      1458/master
Output above indicates that Postfix listens on loopback interface only. To fix that add/change /etc/postfix/main.cf to:
inet_interfaces = all
and restart Postfix.
Now output should be like:
# netstat -vatupn | grep 25
tcp        0      0 '''0.0.0.0:25'''                  0.0.0.0:*                  LISTEN      6525/master       
tcp        0      0 :::25                      :::*                        LISTEN      6525/master
and you should see log output when email is sent to server.
If you can see '''log output''' but it '''shows error''' like:
Aug 21 08:44:10 hostname postfix/smtpd[9981]: NOQUEUE: reject: RCPT from nm21-vm5.bullet.mail.ir2.yeah.com[1.2.3.4]: 554 5.7.1 <callback@morserver.com>: '''Relay access denied'''; from=<sender@yeah.com> to=<callback@morserver.com> proto=ESMTP helo=<nm21-vm5.bullet.mail.ir2.yeah.com>
Make sure that domain name which points to MOR server ( morserver.com in example above ) is added to /etc/postfix/main.cf
...
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain, '''morserver.com'''
...
===Check if you have correctly setup a CLI===
1. Connect to MOR system console and launch this command:
tail -f /tmp/mor_debug.txt
2. Now send an email to system to initiate a callback.
3. If in opened console you get such output:
--- !map:HashWithIndifferentAccess 
         
param1: "1003"     
                         
action: email_callback 
                     
subject: callback   
                         
param2: "1003"   
                           
param3: "1004"   
                           
controller: emails                           
email2callback''' fail by auth_callerid: 1003'''
That means you set the CLI wrong or have not set it at all.
<br><br>
'''example of output after a  successful command'''
--- !map:HashWithIndifferentAccess   
         
param1: "1003"       
                         
action: email_callback 
                       
subject: callback 
                           
param2: "1003" 
                               
param3: "1004" 
                               
controller: emails                             
'''email2callback by 1003 authenticated.'''
<br><br>
'''To check if you have successfully enabled email callback for CLI use this command:'''
mysql mor -e "select * from callerids;"
You will get a similar output:
+----+------+-----------+-------------+---------------------+--------+---------------------+---------------------+--------+---------+----------------+
| id | cli  | device_id | description | added_at            | banned | created_at          | updated_at          | ivr_id | comment | email_callback |
+----+------+-----------+-------------+---------------------+--------+---------------------+---------------------+--------+---------+----------------+
|  1 | 1003 |        9 | asdfasd    | 2011-08-19 11:11:42 |      0 | 2011-08-19 11:11:42 | 2011-08-19 11:11:42 |      0 |        |              1 |
+----+------+-----------+-------------+---------------------+--------+---------------------+---------------------+--------+---------+----------------+
Search for your CLI, email_callback = 1 means that email_callback is enabled for this CLI.
<br><br>
<br><br>



Latest revision as of 08:06, 28 August 2014

About

Callback Addon is needed in order to use email/sms callback.

Description

This function receives email and initiates callback using details in this email.

A device can have one CallerID from which it is able to initiate Callback.

Admin sets up the email box, which should be monitored for callback execution.

An SMS to initiate callback can look like:

For CallerID change: change*new_callerid

For callback inititation:

  • first_number#second_number
  • first_number - will ask destination

Then SMS gateway should send email to MOR to initiate callback in following format:

CallerID change:

  • Email subject: change
  • Email body: old callerid\nnew callerid, (\n) means new line

Callback inititation:

  • Email subject: callback
  • Email body:
MOR_PARAM1 auth_callerid
MOR_PARAM2 first_number
MOR_PARAM3 second_number


NOTE: email format should be plain, not html!



SMS Gateway example

Sms gateway.png
http://www.sms-gateways.co.uk/sms-gateway-pricing.shtml



Inner mechanics

1. SMS gateway sends email to specified address (example callback@hostname.com) in the following format:

CallerID change:

  • Email subject: change
  • Email body: old callerid\nnew callerid, (\n) means new line

Callback inititation:

  • Email subject: callback
  • Email body:
MOR_PARAM1 auth_callerid
MOR_PARAM2 first_number
MOR_PARAM3 second_number


2. Postfix server gets email and sends to /usr/local/mor/mor_email2callback.sh script

(It is already configured for you)

This is configured in /etc/aliases file:

callback: "|/usr/local/mor/mor_email2callback.sh"


3. /usr/local/mor/mor_email2callback.sh script parses email and sends everything to MOR.

(It is already configured for you)

wget -o /dev/null -O /dev/null "http://localhost/billing/emails/email_callback?subject=$subject&param1=$param1&param2=$param2&param3=$param3"

4. MOR GUI initiates callback using AMI command Originate.




Email Callback Setup example

In order Email Callback would work you must:

  • Have a working Device in MOR
  • Have a CLI set for that device with Use for Email Callback option selected
  • Point your domain MX record to MOR system (required when you go to Production). During this example we will send an email from the MOR system itself so MX record setup is not needed to test this feature.



Step 1. Configure MOR

1. Create a new sip device for a user. In this example created new device has an extension 1003. We will use this extension number as Source phone number in this callback example.

2. Create a new CLI for that device

1) Go to device list: SETTINGS -> Users -> Devices

2) Click the Icon clis.png button on the device you have just created.

3) Create a new CLI as described here, when creating be sure to select Use for Email Callback

Step 2. Test Email Callback from MOR system itself

For testing we will use Linux utility called mail. To make sure it is installed run this command:

yum -y install mailx

1. Go to MOR system's console (shell) and run this command:

mail -s callback callback@localhost  

P.S. when you will go to production @localhost will be @your_domain.com and email can be sent from any email client.

2. After launching command mentioned in 1. enter this text as email body:

MOR_PARAM1 1003 
MOR_PARAM2 1003
MOR_PARAM3 1004


Explanation:

MOR_PARAM1 1003 - 1003 here is a CLI you have configured in Step 1. when configured MOR

MOR_PARAM2 1003 - source device where callback should call first

MOR_PARAM3 1004 - destination where callback should call to. Can be any valid phone number, for example 37067531060 or extension in MOR. In this example we used an extension 1003 in MOR.

3. Press CTRL+D to finally send an email.

If you will be asked any questions, just press enter.


4. Now you should receive the call.




Troubleshooting

Check if email reaches the server

1. In console execute this command:

tail -f /var/log/maillog

2. Now send the email to the system

3. If you get something similar:

Aug 19 10:50:13 localhost postfix/pickup[8237]: 84E4D3E0475: uid=0 from=<root>

Aug 19 10:50:13 localhost postfix/cleanup[9095]: 84E4D3E0475: message-id=<20110819075013.84E4D3E0475@localhost.localdomain>

Aug 19 10:50:13 localhost postfix/qmgr[2821]: 84E4D3E0475: from=<root@localhost.localdomain>, size=381, nrcpt=1 (queue active)

Aug 19 10:50:13 localhost postfix/local[9097]: 84E4D3E0475: to=<callback@localhost.localdomain>, orig_to=<callback@localhost>, relay=local, delay=0.21, delays=0.04/0/0/0.16, dsn=2.0.0, status=sent (delivered to command: /usr/local/mor/mor_email2callback.sh)

Aug 19 10:50:13 localhost postfix/qmgr[2821]: 84E4D3E0475: removed

Aug 19 11:25:42 localhost postfix/qmgr[2821]: D86A63E0471: from=<root@localhost.localdomain>, size=367, nrcpt=1 (queue active)


that means that email was successfully received in MOR system and arguments were passed to a callback script.

If you cannot see any log output when email is sent to server, make sure that Postix is running and listening on Public IP or all IPs:

# netstat -vatupn | grep 25
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      1458/master         
tcp        0      0 ::1:25                      :::*                        LISTEN      1458/master

Output above indicates that Postfix listens on loopback interface only. To fix that add/change /etc/postfix/main.cf to:

inet_interfaces = all

and restart Postfix.

Now output should be like:

# netstat -vatupn | grep 25
tcp        0      0 0.0.0.0:25                  0.0.0.0:*                   LISTEN      6525/master         
tcp        0      0 :::25                       :::*                        LISTEN      6525/master

and you should see log output when email is sent to server.


If you can see log output but it shows error like:

Aug 21 08:44:10 hostname postfix/smtpd[9981]: NOQUEUE: reject: RCPT from nm21-vm5.bullet.mail.ir2.yeah.com[1.2.3.4]: 554 5.7.1 <callback@morserver.com>: Relay access denied; from=<sender@yeah.com> to=<callback@morserver.com> proto=ESMTP helo=<nm21-vm5.bullet.mail.ir2.yeah.com>

Make sure that domain name which points to MOR server ( morserver.com in example above ) is added to /etc/postfix/main.cf

...
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain, morserver.com
...

Check if you have correctly setup a CLI

1. Connect to MOR system console and launch this command:

tail -f /tmp/mor_debug.txt

2. Now send an email to system to initiate a callback.

3. If in opened console you get such output:

--- !map:HashWithIndifferentAccess

param1: "1003"

action: email_callback

subject: callback

param2: "1003"

param3: "1004"

controller: emails

email2callback fail by auth_callerid: 1003


That means you set the CLI wrong or have not set it at all.

example of output after a successful command

--- !map:HashWithIndifferentAccess

param1: "1003"

action: email_callback

subject: callback

param2: "1003"

param3: "1004"

controller: emails

email2callback by 1003 authenticated.

To check if you have successfully enabled email callback for CLI use this command:

mysql mor -e "select * from callerids;"


You will get a similar output:

+----+------+-----------+-------------+---------------------+--------+---------------------+---------------------+--------+---------+----------------+
| id | cli  | device_id | description | added_at            | banned | created_at          | updated_at          | ivr_id | comment | email_callback |
+----+------+-----------+-------------+---------------------+--------+---------------------+---------------------+--------+---------+----------------+
|  1 | 1003 |         9 | asdfasd     | 2011-08-19 11:11:42 |      0 | 2011-08-19 11:11:42 | 2011-08-19 11:11:42 |      0 |         |               1 |
+----+------+-----------+-------------+---------------------+--------+---------------------+---------------------+--------+---------+----------------+


Search for your CLI, email_callback = 1 means that email_callback is enabled for this CLI.

SMS Callback

It is possible to setup SMS Callback using such provider as: https://www.aql.com/sms/sms-to-email/



See also