How to send notification on some action from Splynx


#1

To send notification on some action from Splynx you can use hooks (Config/Integrations/Hooks).
Attention!!! beginning from Splynx v.1.3

First of all, you have to know how does it work. “Hook” is listening to event you choose and if it done, it runs script you wrote in “path”-field. By the way, hook can send data-array that call this event. Let’s create a new hook:

Before creating hook you have to put php-script in home-folder and give permissions 755:

chmod 755 script-file.php

And now, simple script - how to send email notification. Of course, you can use your own script that do something else.

#!/usr/bin/php
<?php

/*
* don`t edit this block !!!! 
*/
// Define STDIN
defined('STDIN') OR define('STDIN', fopen('php://stdin', 'r'));

// Get all data. Its is in JSON so we must decode it
$data = fgets(STDIN);

// Decode JSON
$data = json_decode($data, true);


/*
* to send email edit this block 
*/
$model = print_r($data,1); //print data-array
//send email
$to  = "mail_box_to@semple.com" ;                       //set your email
$subject = "Splynx test send-mailer"; 
$message = "{$model} \n 
Customer \"{$data['attributes']['name']}\" was created {$data['date']} by {$data['source']}";
$headers = "From: Admin <mail_box_from@semple.com>\r\n";

mail($to, $subject, $message, $headers);

So, when a new customer will be created, we will receive an email:

Attention!!!
To send email we used mail-server - Sendmail, and by default it send email only in local-network. So, if you want to send an email to “the world”, you have to reconfigure sendmail.
Run this command

sudo dpkg-reconfigure exim4-config

and use this manual - https://www.digitalocean.com/community/tutorials/how-to-install-the-send-only-mail-server-exim-on-ubuntu-12-04

That is all.

WBR, Splynx team.


Integration With Jabber
Splynx Hooks no working
Customers SMS New Invoice Notification
Customers SMS New Invoice Notification
Must add some SMS and email Features
#2

Hi Nikolay,
I’m trying creating hook to send sms when a new customer created.



Script:

<?php

/*
* don`t edit this block !!!! 
*/
// Define STDIN
defined('STDIN') OR define('STDIN', fopen('php://stdin', 'r'));

// Get all data. Its is in JSON so we must decode it
$data = fgets(STDIN);

// Decode JSON
$data = json_decode($data, true);

$message = "{$data['attributes']['name']}";
$to = "{$data['attributes']['phone']}";
$to = preg_replace('/\D/', '', $to);

// please set
$smapisuser = "user";
$smsapipassword = "pass";

$rand = mt_rand (1, 8);

$url = "http://192.168.11.5/cgi/WebCGI?1500101=account={$smapisuser}&password={$smsapipassword}&port={$rand}&destination={$to}&content={$message}";

$curl = curl_init();
curl_setopt_array($curl, array(
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_URL => $url,
    CURLOPT_USERAGENT => 'CURL'
));
$resp = curl_exec($curl);
curl_close($curl);
//print $resp;

But not get any response.
First of all I’m not sure that splynx invites the script on some action…
When I add some lines in code for creating log file, and after that creating new customer, log file not generated.


#3

I had the same problem and Nik seemed to fix it and replied with this:
process “splynx_queue” was not running


#4

Hello, please, try use script without this code:

/*
* don`t edit this block !!!! 
*/
// Define STDIN
defined('STDIN') OR define('STDIN', fopen('php://stdin', 'r'));

// Get all data. Its is in JSON so we must decode it
$data = fgets(STDIN);

// Decode JSON
$data = json_decode($data, true);

if script will be running, it means something with “splynx_queue”. Then you should try:

/etc/init.d/splynx_queue restart

But if script will not be running you should upgrade your system, like:

apt-get update && apt-get dist-upgrade

#5

Hi,
i change code without this part.
On manuel run php I get sms, script is ok.

Process splynx_queue exists, i restarted him.
Command:
apt-get update && apt-get dist-upgrade
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

I changed Events to Create Customers, Edit customers
After edit customer in splynx or add new…not responce.
Now I’m sure the script not run after this events, but not understand why.


#6

Hi @zeljko,

please create the ticket for this issue and we will check on your install.


#7

Hi, Alex told me that it’s possible to create a script for sending SMS notification to customer when new ticket is created


#8

@Nikolay can you please write such script and share it with others ?


#9

@zeljko

looks like first line

is critical and should exists on file (as first line)

and mode should be 755 (executable)


#10

Oh…stupid mistake… :slightly_smiling_face:
From the beginning it was a problem…
THANKS!


#11

Hi,
I would like create hook for same specific event like:

  1. Change status of customer - blocked/active…
  2. Change password of customer
    For now, it’s only possible definite event on Edit customer.

#12

You should use PHP for understanding what are doing …

you receive old attributes and new, you can compare it …

@Nikolay can you share some example ?


#13

Hi, for example, I used situation when password was modified:

#!/usr/bin/php
<?php


/*
* don`t edit this block !!!!
*/
// Define STDIN
defined('STDIN') OR define('STDIN', fopen('php://stdin', 'r'));

// Get all data. Its is in JSON so we must decode it
$data = fgets(STDIN);

// Decode JSON
$data = json_decode($data, true);

/*
* to send email edit this block
*/
$log_file = '/tmp/log_file.txt';   // I used log-file to see what happens
$model = print_r($data,1); //print data-array
file_put_contents($log_file, "{$model}\n", FILE_APPEND); // print data-array in file

$pass_changed = array_key_exists('password', $data['changed_attributes']); // check if password was modified
if ($pass_changed) {  // if pass was modified, then do something 
    file_put_contents($log_file, "old password - {$data['changed_attributes']['password']['value']}\n",  FILE_APPEND); // in this example I print old password
}

#14

Hi,
ok now I understand logic. It works great!:slightly_smiling_face:
Thanks!


#15

How would we add a hook when a customer’s service is changed from new -> active?


#16

Hi Spencer,

exactly the same as in my example How to send notification on some action from Splynx but there I’m checking “if password was modified” and you have to check if status modified.


#17

Ok, I get how it’s working.