← All changes
|
app/Http/Controllers/ChatMessageParserController.php
+3
-48
trunk
→
2.1.1
View file →
| @@ -25,15 +25,8 @@ | ||
| 25 | 25 | * @return mixed |
| 26 | 26 | */ |
| 27 | 27 | public function handleTelegramWebhook(Request $request, HandleTelegramEvent $handler, $token) |
| 28 | 28 | { |
| 29 | - if (!$this->verifyWebhookSignature('telegram', $request)) { | |
| 30 | - return $this->sendError([ | |
| 31 | - 'message' => __('Invalid request signature.', 'fluent-support'), | |
| 32 | - 'status' => false | |
| 33 | - ], 403); | |
| 34 | - } | |
| 35 | - | |
| 36 | 29 | try { |
| 37 | 30 | return $this->sendSuccess([ |
| 38 | 31 | 'message' => __('Response has been successfully recorded', 'fluent-support'), |
| 39 | 32 | 'status' => true, |
| @@ -48,30 +41,16 @@ | ||
| 48 | 41 | } |
| 49 | 42 | |
| 50 | 43 | /** |
| 51 | 44 | * handleSlackEvent responsible for getting information from integrated slack request and response |
| 52 | - * @param Request $request | |
| 53 | 45 | * @param HandleSlackEvent $handler |
| 54 | 46 | * @param $token |
| 55 | 47 | * @return array |
| 56 | 48 | */ |
| 57 | - public function handleSlackEvent(Request $request, HandleSlackEvent $handler, $token) | |
| 49 | + public function handleSlackEvent(HandleSlackEvent $handler, $token) | |
| 58 | 50 | { |
| 59 | - if (!$this->verifyWebhookSignature('slack', $request)) { | |
| 60 | - return $this->sendError([ | |
| 61 | - 'message' => __('Invalid request signature.', 'fluent-support'), | |
| 62 | - 'status' => false | |
| 63 | - ], 403); | |
| 64 | - } | |
| 65 | - | |
| 66 | - if ($request->getSafe('type', 'sanitize_text_field') === 'url_verification') { | |
| 67 | - return new \WP_REST_Response($request->getSafe('challenge', 'sanitize_text_field'), 200, [ | |
| 68 | - 'Content-Type' => 'text/plain; charset=utf-8' | |
| 69 | - ]); | |
| 70 | - } | |
| 71 | - | |
| 72 | - try { | |
| 73 | - return $this->sendSuccess([ | |
| 51 | + try{ | |
| 52 | + $this->sendSuccess([ | |
| 74 | 53 | 'message' => 'received', |
| 75 | 54 | 'result' => $handler->handleEvent($token) |
| 76 | 55 | ]); |
| 77 | 56 | } catch (\Exception $e) { |
| @@ -79,30 +58,6 @@ | ||
| 79 | 58 | 'message' => Helper::getSafeErrorMessage($e), |
| 80 | 59 | 'status' => false |
| 81 | 60 | ]); |
| 82 | 61 | } |
| 83 | - } | |
| 84 | - | |
| 85 | - /** | |
| 86 | - * Verify webhook signature using platform-specific logic. | |
| 87 | - * | |
| 88 | - * Pro plugin or third-party code may hook into the filter | |
| 89 | - * 'fluent_support/verify_webhook_signature_{platform}' to enable | |
| 90 | - * cryptographic signature verification. When no verifier is | |
| 91 | - * registered, fall back to the existing token-based validation | |
| 92 | - * handled by the downstream webhook handlers. | |
| 93 | - * | |
| 94 | - * @param string $platform 'telegram' or 'slack' | |
| 95 | - * @param Request $request | |
| 96 | - * @return bool | |
| 97 | - */ | |
| 98 | - private function verifyWebhookSignature($platform, Request $request) | |
| 99 | - { | |
| 100 | - $hookName = 'fluent_support/verify_webhook_signature_' . $platform; | |
| 101 | - | |
| 102 | - if (!has_filter($hookName)) { | |
| 103 | - return true; | |
| 104 | - } | |
| 105 | - | |
| 106 | - return (bool) apply_filters($hookName, false, $request); | |
| 107 | 62 | } |
| 108 | 63 | } |