| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentSupport\App\Http\Controllers; |
| 4 |
|
| 5 |
use FluentSupport\Framework\Http\Request\Request; |
| 6 |
use FluentSupport\App\Services\Helper; |
| 7 |
use FluentSupport\App\Services\ThirdParty\HandleSlackEvent; |
| 8 |
use FluentSupport\App\Services\ThirdParty\HandleTelegramEvent; |
| 9 |
|
| 10 |
/** |
| 11 |
* ChatMessageParserController class is responsible for getting information from integrated 3rd party request and response |
| 12 |
* @package FluentSupport\App\Http\Controllers |
| 13 |
* |
| 14 |
* @version 1.0.0 |
| 15 |
*/ |
| 16 |
|
| 17 |
class ChatMessageParserController extends Controller |
| 18 |
{ |
| 19 |
/** |
| 20 |
* handleTelegramWebhook will get the content from telegram, check the data validity and create response in a ticket |
| 21 |
* @param Request $request |
| 22 |
* @param HandleTelegramEvent $handler |
| 23 |
* @param string $token |
| 24 |
* @throws Exception |
| 25 |
* @return mixed |
| 26 |
*/ |
| 27 |
public function handleTelegramWebhook(Request $request, HandleTelegramEvent $handler, $token) |
| 28 |
{ |
| 29 |
try { |
| 30 |
return $this->sendSuccess([ |
| 31 |
'message' => __('Response has been successfully recorded', 'fluent-support'), |
| 32 |
'status' => true, |
| 33 |
'data' => $handler->handleEvent($request->all(), $token) |
| 34 |
]); |
| 35 |
} catch (\Exception $e) { |
| 36 |
return $this->sendError([ |
| 37 |
'message' => Helper::getSafeErrorMessage($e), |
| 38 |
'status' => false |
| 39 |
]); |
| 40 |
} |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* handleSlackEvent responsible for getting information from integrated slack request and response |
| 45 |
* @param HandleSlackEvent $handler |
| 46 |
* @param $token |
| 47 |
* @return array |
| 48 |
*/ |
| 49 |
public function handleSlackEvent(HandleSlackEvent $handler, $token) |
| 50 |
{ |
| 51 |
try{ |
| 52 |
$this->sendSuccess([ |
| 53 |
'message' => 'received', |
| 54 |
'result' => $handler->handleEvent($token) |
| 55 |
]); |
| 56 |
} catch (\Exception $e) { |
| 57 |
return $this->sendError([ |
| 58 |
'message' => Helper::getSafeErrorMessage($e), |
| 59 |
'status' => false |
| 60 |
]); |
| 61 |
} |
| 62 |
} |
| 63 |
} |
| 64 |
|