-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.php
More file actions
147 lines (139 loc) · 4.5 KB
/
test.php
File metadata and controls
147 lines (139 loc) · 4.5 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
140
141
142
143
144
145
146
147
<?php
require_once 'vendor/autoload.php';
use Nigel\FreescoutWebhookParser\FreeScoutWebhookParser;
// Real FreeScout webhook data
$webhookData = '{
"id": 36,
"number": 36,
"threadsCount": 0,
"type": "email",
"folderId": 1,
"status": "active",
"state": "published",
"subject": "Problem with the flux capacitor",
"preview": "Hi there is a problem with my flux capacitor. Can you please check it\u2019s installed correctly?",
"mailboxId": 1,
"assignee": null,
"createdBy": {
"id": 27,
"type": "customer",
"firstName": "Marty",
"lastName": null,
"photoUrl": "",
"email": "mcfly_42@pm.me"
},
"createdAt": "2025-04-09T09:13:05Z",
"updatedAt": "2025-04-09T09:13:06Z",
"closedBy": null,
"closedByUser": null,
"closedAt": null,
"userUpdatedAt": null,
"customerWaitingSince": {
"time": "2025-04-09T09:13:05Z",
"friendly": "Just now",
"latestReplyFrom": "customer"
},
"source": {
"type": "email",
"via": "customer"
},
"cc": [],
"bcc": [],
"customer": {
"id": 27,
"type": "customer",
"firstName": "Marty",
"lastName": null,
"photoUrl": "",
"email": "mcfly_42@pm.me"
},
"_embedded": {
"threads": [
{
"id": 89,
"type": "customer",
"status": "active",
"state": "published",
"action": {
"type": "",
"text": "Marty started a new conversation #36",
"associatedEntities": []
},
"body": " <div><br><\/div><div dir=\"auto\">Hi there is a problem with my flux capacitor. Can you please check it\u2019s installed correctly?<\/div> ",
"source": {
"type": "email",
"via": "customer"
},
"customer": {
"id": 27,
"type": "customer",
"firstName": "Marty",
"lastName": null,
"photoUrl": "",
"email": "mcfly_42@pm.me"
},
"createdBy": {
"id": 27,
"type": "customer",
"firstName": "Marty",
"lastName": null,
"photoUrl": "",
"email": "mcfly_42@pm.me"
},
"assignedTo": null,
"to": [
"support@demo.freescout.net"
],
"cc": [],
"bcc": [],
"createdAt": "2025-04-09T09:13:05Z",
"openedAt": null,
"_embedded": {
"attachments": []
}
}
]
},
"customFields": [
{
"id": 1,
"name": "Priority",
"value": "",
"text": ""
},
{
"id": 2,
"name": "Purchase Date",
"value": "",
"text": ""
}
]
}';
try {
// Create parser instance with webhook data
$parser = new FreeScoutWebhookParser($webhookData);
// Test 1: Parse function with showAll=false (should return WebhookMessageData object)
echo "Test 1: Parse function with showAll=false\n";
$result = $parser->parse(false);
echo "Ticket ID: " . $result->getData()['id'] . "\n";
echo "Ticket Number: " . $result->getData()['number'] . "\n";
echo "Subject: " . $result->getSubject() . "\n";
echo "Preview: " . $result->getData()['preview'] . "\n";
echo "Status: " . $result->getStatus() . "\n";
echo "Type: " . $result->getType() . "\n";
echo "Customer Name: " . $result->getData()['customer']['firstName'] . "\n";
echo "Customer Email: " . $result->getData()['customer']['email'] . "\n";
echo "Created At: " . $result->getData()['createdAt'] . "\n";
echo "Thread Body: " . $result->getData()['_embedded']['threads'][0]['body'] . "\n";
echo "Custom Fields:\n";
print_r($result->getData()['customFields']);
echo "\n";
// Test 2: Parse function with showAll=true (should return raw data)
echo "Test 2: Parse function with showAll=true\n";
$result = $parser->parse(true);
echo "Raw Data Structure:\n";
print_r($result);
} catch (\Exception $e) {
echo "Error: " . $e->getMessage() . "\n";
echo "Trace: " . $e->getTraceAsString() . "\n";
}