Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] subject Regexfilter #10

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,29 @@ An plugin for [osTicket](https://osticket.com) which posts notifications to a [S
Install
--------
Clone this repo or download the zip file and place the contents into your `include/plugins` folder.
Login (admin level) in your Osticket activate and visit settings:
* Webhook URL
Required: this is your Slack webhook URL
* Ignore when subject equals regex
Optional: do you want to ignore specific subjects? Set a PHP regex here.
leave empty to allow all tickets to be sent to slack

Changelog
---------
0.3 - 17 december 2016
[bugfix] "PHP syntax error" by ramonfincken

0.2 - 17 december 2016
[feature] "Ignore when subject equals regex" by ramonfincken

0.1 - 3 december 2014
[release] "Init" by thammanna

Authors
-------
thammanna https://github.com/thammanna/osticket-slack
ramonfincken https://github.com/ramonfincken/osticket-slack

Info
------
This plugin uses CURL and tested on osTicket-1.8.
This plugin uses CURL and tested on osTicket-1.8 and osTicket-1.9.12.
Binary file added ignore_regex.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion slack/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ function getOptions() {
'slack-webhook-url' => new TextboxField(array(
'label' => 'Webhook URL',
'configuration' => array('size'=>100, 'length'=>200),
)),
)),
'slack-regex-subject-ignore' => new TextboxField(array(
'label' => 'Ignore when subject equals regex',
'configuration' => array('size'=>100, 'length'=>200),
)),
);
}
}
2 changes: 1 addition & 1 deletion slack/plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

return array(
'id' => 'osticket:slack',
'version' => '0.1',
'version' => '0.3',
'name' => 'Slack notifier',
'author' => 'Thammanna Jammada',
'description' => 'Notify Slack on new ticket.',
Expand Down
24 changes: 19 additions & 5 deletions slack/slack.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

require_once(INCLUDE_DIR.'class.signal.php');
require_once(INCLUDE_DIR.'class.plugin.php');
require_once('config.php');
Expand All @@ -13,7 +12,11 @@ function bootstrap() {

function onTicketCreated($ticket){
try {
global $ost;
global $ost;

$regex_subject_ignore = $this->getConfig()->get('slack-regex-subject-ignore');
$ticket_subject = $ticket->getSubject();

$payload = array(
'attachments' =>
array (
Expand All @@ -26,7 +29,7 @@ function onTicketCreated($ticket){
'fields' =>
array(
array (
'title' => $ticket->getSubject(),
'title' => $ticket_subject,
'value' => "created by " . $ticket->getName() . "(" . $ticket->getEmail()
. ") in " . $ticket->getDeptName() . "(Department) via "
. $ticket->getSource(),
Expand All @@ -36,7 +39,18 @@ function onTicketCreated($ticket){
),
),
);



/** Filter on subject based on regex ? */
if(isset($regex_subject_ignore) && $regex_subject_ignore != '') {
if(preg_match($regex_subject_ignore, $ticket_subject)) {
error_log('The message slack notification was ignored due to subject ('.htmlspecialchars($ticket_subject).') regex ('.htmlspecialchars($regex_subject_ignore).') ignore match.');
return;
}

}
/** /Filter on subject based on regex ? */

$data_string = utf8_encode(json_encode($payload));
$url = $this->getConfig()->get('slack-webhook-url');

Expand Down Expand Up @@ -64,4 +78,4 @@ function onTicketCreated($ticket){
error_log('Error posting to Slack. '. $e->getMessage());
}
}
}
}