PluginProbe
Fluent Support – Helpdesk & Customer Support Ticket System / 2.4.5
Fluent Support – Helpdesk & Customer Support Ticket System v2.4.5
2.4.5 2.4.0 2.3.2 2.3.1 2.3.0 2.2.1 2.2.0 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.10.5 1.4.0 1.4.1 1.4.2 1.4.5 1.4.6 1.4.7 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 All 69 releases
← All changes | app/Services/ThirdParty/HandleTelegramEvent.php +8 -16 2.4.0 → 2.4.5 View file →
@@ -13,25 +13,23 @@
13 13 {
14 14
15 15
16 16 /**
17 - * handleEvent method is responsible for handling telegram events
17 + * Reply to (and optionally close) a ticket from a Telegram bot message.
18 + *
18 19 * @param array $payload
19 20 * @param string $token
20 - * @return array
21 + * @return array|false
21 22 * @throws Exception
22 23 */
23 24 public function handleEvent ($payload, $token)
24 25 {
25 26
26 - // Check if user have the pro version installed or not
27 27 $this->verifyProVersion();
28 28
29 - // Check if the token is valid or not
30 29 $this->validateToken($token);
31 30
32 31 try {
33 - // Build the response or throw error
34 32 $responseData = $this->parseResponseData($payload);
35 33
36 34 } catch (\Exception $exception) {
37 35 return false;
@@ -48,11 +46,10 @@
48 46 if (!$agent) {
49 47 return false;
50 48 }
51 49
52 - // The agent comes from the Telegram sender id, not a logged-in user, so check
53 - // access explicitly: every mailbox notifies the same chat, and an agent excluded
54 - // from a box must not reply to or close that box's tickets from here.
50 + // The agent comes from the Telegram sender, not a logged-in user, and every
51 + // mailbox posts to the same chat. Enforce mailbox restrictions here.
55 52 if (!(new AgentTicketAccess())->canAccess($agent, $ticket)) {
56 53 return false;
57 54 }
58 55
@@ -62,9 +59,8 @@
62 59 'source' => 'telegram'
63 60 ];
64 61
65 62 if(!empty($data['content'])) {
66 - // Create the response
67 63 (new ResponseService)->createResponse($data, $agent, $ticket);
68 64 }
69 65
70 66 if(!empty($responseData['command']) && $responseData['command'] == 'close_ticket') {
@@ -75,11 +71,10 @@
75 71 }
76 72
77 73
78 74 /**
79 - * verifyProVersion method will check if the pro version is installed or not
80 75 * @throws Exception
81 - * @return boolean | Exception
76 + * @return bool
82 77 */
83 78 private function verifyProVersion ()
84 79 {
85 80 if (!defined('FLUENTSUPPORTPRO')) {
@@ -89,12 +84,11 @@
89 84 return true;
90 85 }
91 86
92 87 /**
93 - * validateToken method will check if the token is valid or not
94 88 * @param string $token
95 89 * @throws Exception
96 - * @return boolean | Exception
90 + * @return bool
97 91 */
98 92 private function validateToken ($token)
99 93 {
100 94 if (!hash_equals(\FluentSupportPro\App\Services\Integrations\Telegram\TelegramHelper::getWebhookToken(), $token)) {
@@ -103,10 +97,8 @@
103 97 return true;
104 98 }
105 99
106 100 /**
107 - * parseResponseData method will parse the response data and return an array with
108 - * response text and ticket id and agent id
109 101 * @param array $payload
110 102 * @throws Exception
111 103 * @return array
112 104 */
@@ -115,9 +107,9 @@
115 107 $responseData = \FluentSupportPro\App\Services\Integrations\Telegram\TelegramHelper::parseTelegramBotPayload($payload);
116 108
117 109 if ( is_wp_error( $responseData ) ) {
118 110 /*
119 - * Action on telegram payload error when replying ticket from telegram
111 + * Fires when a Telegram reply payload can't be parsed.
120 112 *
121 113 * @since v1.0.0
122 114 * @param array $responseData
123 115 * @param array $payload