-
Notifications
You must be signed in to change notification settings - Fork 1
/
tickets.php
executable file
·159 lines (137 loc) · 4.9 KB
/
tickets.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<?php
require "creds.php";
session_start();
header("Content-Type: text/xml");
echo '<?xml version="1.0" encoding="UTF-8" standalone="no" ?>';
function gather($digits,$action,$audio)
{
echo "<Gather numDigits='$digits' action='$action'>";
echo "<Play>$audio</Play>";
echo "</Gather>";
}
function play($action,$audio)
{
echo "<Play action='$action'>$audio</Play>";
}
function forward($location)
{
echo "<Forward >$location</Forward>";
}
function jira($app, $tix)
{
global $jira_hostname;
global $jira_username;
global $jira_password;
//https://developer.atlassian.com/cloud/jira/platform/integrating-with-jira-cloud/
//https://developer.atlassian.com/cloud/jira/platform/jira-rest-api-basic-authentication/
$release_notes_id = "customfield_10505";
$fixVersions = "fixVersions";
$url = "https://$jira_hostname/rest/api/2/issue/";
switch ($app) {
case 1:
$url .= "API-";
break;
case 2:
$url .= "OMP-";
break;
case 3:
$url .= "NMS-";
break;
}
$url .= $tix;
$ch = curl_init($url);
$headers = array('Content-Type:application/json');
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_USERPWD, $jira_username . ":" . $jira_password);
$json = curl_exec($ch);
if ($json!= null) // Convert JSON to PHP object
$phpObj = json_decode($json,true);
$speech = "<speak>";
if (!isset($phpObj) || !isset($phpObj['key']))
{
return "We are unable to locate your ticket. ";
}
$speech .="Ticket ".substr($phpObj['key'],0,4) ."<say-as interpret-as=\"digits\">".substr($phpObj['key'],4)."</say-as>" .
" a ticket with type ". $phpObj['fields']['issuetype']['name']. " with the title of '".
$phpObj['fields']['summary']."' is in status '".$phpObj['fields']['status']['name']."'.";
if ($phpObj['fields']['status']['name']== "Released"){
foreach ($phpObj['fields']['fixVersions'] as &$value)
$speech .= "<p>This ticket has been released in version ". $value['name']."</p>";
}
else if ($phpObj['fields']['fixVersions'])
{
$speech .= " <p>This ticket will be in a upcoming release. Version or versions will be ";
foreach ($phpObj['fields']['fixVersions'] as &$value) {
$speech .= $value['name'].", ";
}
$speech .= " </p>";
}
$give_release_notes = false;
if ($phpObj['fields']['status']['name']== "Testing Complete"
|| $phpObj['fields']['status']['name']== "Ready for Testing"
|| $phpObj['fields']['status']['name']== "Done"
|| $phpObj['fields']['status']['name']== "Pending Merge"
|| $phpObj['fields']['status']['name']== "In Testing"
|| $phpObj['fields']['status']['name']== "Released"
)
$give_release_notes=true;
if ($give_release_notes && isset($phpObj['fields']['customfield_10505'] ))
{
if (isset($phpObj['fields']['customfield_11100']) && isset($phpObj['fields']['customfield_11100']['value'])
&& $phpObj['fields']['customfield_11100']['value']=="Yes" )
$speech .= "<p>This ticket has been marked internal so no further information is available</p>" ;
else {
$speech .= "<p>The release notes for this ticker are as follows</p> " . $phpObj['fields']['customfield_10505']."";
}
}
$speech .= "</speak>";
return $speech;
}
function awsSpeech($speech)
{
global $aws_token;
global $aws_key;
require 'vendor/autoload.php';
$s3 = new Aws\Polly\PollyClient([
'version' => 'latest',
'region' => 'us-west-2',
'credentials' => [
'key' => $aws_token,
'secret' => $aws_key
]
]);
$result = $s3->synthesizeSpeech([
'LexiconNames' => [],
'OutputFormat' => 'mp3',
'SampleRate' => '8000',
'Text' => $speech,
'TextType' => "ssml",
'VoiceId' => 'Joanna',
]);
$tmpName = "polly".uniqid();
file_put_contents("/tmp/".$tmpName.".mp3",
$result['AudioStream']->getContents() );
$cmd1 = '/usr/bin/mpg123 -w '."/tmp/".$tmpName.
'.wav '."/tmp/".$tmpName.'.mp3';
$cmd2 = '/usr/bin/sox '."/tmp/".$tmpName.'.wav '.
' -e mu-law -r 8000 -c 1 -b 8 '."audio/".$tmpName.".wav";
exec($cmd1);
exec($cmd2);
return "audio/".$tmpName.".wav";
}
if (!isset($_REQUEST["case"])) {
$speech = "<speak>Thank you for calling the netsapiens automated ticket status system. ";
$speech .= "For API tickets press 1. For Portal tickets press 2. For NMS or core tickets press 3</speak>";
gather(1,"tickets.php?case=requestNumber",awsSpeech($speech));
}
else if ($_REQUEST["case"] == "requestNumber") {
$speech = "<speak>Please enter the ticket number.</speak>";
$_SESSION["project"]=$_REQUEST["Digits"];
gather(4,"tickets.php?case=playStatus",awsSpeech($speech));
}
else if ($_REQUEST["case"] == "playStatus") {
$speech = jira($_SESSION["project"],$_REQUEST["Digits"]);
$audioPath = awsSpeech($speech);
play("tickets.php",$audioPath);
}