-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathExample.php
More file actions
139 lines (111 loc) · 3.44 KB
/
Example.php
File metadata and controls
139 lines (111 loc) · 3.44 KB
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
<?php
date_default_timezone_set("America/New_York"); // just in case... you definitely don't need this
include_once('FancyHands.php');
// API Keys
$apiKey = '';
$apiSecret = '';
// Development mode? (won't send task to FancyHands assistants)
$dev = true;
// Initialize the API
$FancyHands = new FancyHands($apiKey, $apiSecret, $dev);
$data = array(
'etc' => 'thing',
'other' => 'yes',
'cheese' => "Test Field",
);
print_r($FancyHands->_echo($data));
// Create A custom request...
$customFields = array(
array(
'type' => 'text',
'required' => false,
'label' => "Test Field",
"description" => "Test Field Description",
"order" => 0,
"field_name" => "test_field"
)
);
print "Creating a new custom request\n";
$expire = strtotime("+1 day");
$request = $FancyHands->custom_create("PHP Custom Test", "PHP Custom Test...", 1, $customFields, $expire);
$key = $request->key;
print "Created custom!\n";
// get it
print "Loading it again: \n";
$r = $FancyHands->custom_get($request->key);
print "Loaded " . $r->title . " (" . $r->uniq . ")\n";
// cancel it
print "Canceling it\n";
if($FancyHands->cancel($request->key)) {
print "Cancelled the request.\n";
}
else {
print "Wasn't able to cancel the request.\n";
}
// get a list of canceled tasks
$query = $FancyHands->custom_get(null, $FancyHands::STATUS_EXPIRED);
foreach($query->requests as $r) {
print("[" . $r->status . "] " . $r->title . " (" . $r->uniq . ")\n");
}
print "Creating a new standard request\n";
$expire = strtotime("+1 day");
$std = $FancyHands->standard_create("PHP Standard Test", "PHP Standard Test...", 1, $expire);
$key = $std->key;
print "Created standard!\n";
print "Creating message!\n";
$FancyHands->standard_messages_create($std->key, "I'm going to cancel this request");
print "Created message!\n";
print "loading request with messages\n";
$r = $FancyHands->standard_get($std->key);
print "loaded request with messages\n";
foreach($r->messages as $message) {
print $message->content . "\n";
}
// cancel it
print "Canceling it\n";
if($FancyHands->cancel($r->key)) {
print "Cancelled the request.\n";
}
else {
print "Wasn't able to cancel the request.\n";
}
// get a list of canceled tasks
$query = $FancyHands->standard_get(null, $FancyHands::STATUS_EXPIRED);
foreach($query->requests as $r) {
print("[" . $r->status . "] " . $r->title . " (" . $r->uniq . ")\n");
}
$conversation = array(
'id'=> 'simple_conversation',
'name'=> 'Simple Conversation',
'version'=> 1.1,
'scripts'=> array(
array(
'id'=> 'step1',
'steps'=> array(
array(
'name'=> 'name',
'type'=> 'text',
'prompt'=> 'Hello my name is $assistant_name, what\'s your name?',
),
array(
'name'=> 'thanks',
'type'=> 'logic_control',
'prompt'=> "Thanks! That's all",
),
)
)
)
);
$expire = strtotime("+1 day");
$call = $FancyHands->call_create("8154553440", $conversation, $expire);
$key = $call->key;
print "Created call!\n";
print "Cancelling\n";
if($FancyHands->cancel($key)) {
print "Success\n";
}
# get a list of canceled tasks
$query = $FancyHands->call_get(null, $FancyHands::STATUS_EXPIRED);
foreach($query->calls as $r) {
print("[" . $r->status . "] " . $r->title . " (" . $r->uniq . ")\n");
}