SocialTalkController.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace Themes\kbgolf\pro\app\Http\Controllers\Auth;
  3. use App\Services\CallApiService;
  4. use App\Http\Controllers\Controller;
  5. use Themes\kbgolf\pro\app\Services\SocialService;
  6. use Illuminate\Http\Request;
  7. use Illuminate\Support\Facades\Log;
  8. class SocialTalkController extends Controller
  9. {
  10. protected $socialService;
  11. public function __construct(SocialService $socialService)
  12. {
  13. $this->socialService = $socialService;
  14. }
  15. public function sendMessage(Request $request)
  16. {
  17. Log::debug($request);
  18. $validatedData = $request->validate([
  19. 'channel_id' => 'required|string',
  20. 'template_object.text' => 'required|string',
  21. 'link_url' => 'nullable|url',
  22. ]);
  23. // Log::debug('검증: ' . json_encode($validatedData));
  24. try {
  25. $response = $this->socialService->sendMessage(
  26. $validatedData['channel_id'],
  27. [
  28. 'message' => $validatedData['template_object']['text'],
  29. 'link_url' => $validatedData['link_url'] ?? null,
  30. ]
  31. );
  32. // Log::debug('결과: ' . $response);
  33. return response()->json(['success' => true, 'message' => '메시지가 성공적으로 전송되었습니다.', 'response' => json_decode($response)]);
  34. } catch (ValidationException $e) {
  35. return response()->json(['success' => false, 'message' => '유효성 검사 오류입니다.', 'errors' => $e->errors()]);
  36. } catch (Exception $e) {
  37. return response()->json(['success' => false, 'message' => '메시지 전송에 실패했습니다.', 'error' => $e->getMessage()]);
  38. }
  39. }
  40. }