← All changes
|
app/Services/Integrations/FluentBot/FluentBotHelper.php
+32
-10
2.3.0
→
2.4.5
View file →
| @@ -263,8 +263,30 @@ | ||
| 263 | 263 | |
| 264 | 264 | return $body; |
| 265 | 265 | } |
| 266 | 266 | |
| 267 | + /** | |
| 268 | + * Reconnect to an in-flight turn and stream its buffered SSE straight to the | |
| 269 | + * browser. Writes directly to the output stream, so it returns nothing on | |
| 270 | + * success; a credentials failure is emitted as an SSE `error` frame because the | |
| 271 | + * caller has already sent SSE headers by this point. | |
| 272 | + */ | |
| 273 | + public function resumeChatStream($chatId, $productId = null) | |
| 274 | + { | |
| 275 | + $credentials = $this->resolveApiCredentials($productId); | |
| 276 | + | |
| 277 | + if (is_wp_error($credentials)) { | |
| 278 | + echo "event: error\n"; | |
| 279 | + echo "data: " . wp_json_encode(['error' => $credentials->get_error_message()]) . "\n\n"; | |
| 280 | + flush(); | |
| 281 | + return; | |
| 282 | + } | |
| 283 | + | |
| 284 | + $url = $this->apiBaseUrl() . '/bots/' . $credentials['botId'] . '/chats/' . $chatId . '/stream'; | |
| 285 | + | |
| 286 | + (new FluentBotAPI($url, $credentials['apiKey']))->makeResumeStreamRequest(); | |
| 287 | + } | |
| 288 | + | |
| 267 | 289 | public function createFeedback($messageId, $reaction, $comment, $productId = null, $chatId = null) |
| 268 | 290 | { |
| 269 | 291 | $credentials = $this->resolveApiCredentials($productId); |
| 270 | 292 | |
| @@ -513,29 +535,29 @@ | ||
| 513 | 535 | private function getModifyResponsePresets(): array |
| 514 | 536 | { |
| 515 | 537 | $presets = [ |
| 516 | 538 | [ |
| 517 | - 'label' => 'Improve Writing', | |
| 539 | + 'label' => __('Improve Writing', 'fluent-support'), | |
| 518 | 540 | 'text' => 'shorten', |
| 519 | 541 | 'description' => 'Use AI to refine the text by removing unnecessary words and making it more concise while retaining the original meaning and key information.' |
| 520 | 542 | ], |
| 521 | 543 | [ |
| 522 | - 'label' => 'Fix Spelling & Grammar', | |
| 544 | + 'label' => __('Fix Spelling & Grammar', 'fluent-support'), | |
| 523 | 545 | 'text' => 'lengthen', |
| 524 | 546 | 'description' => 'Apply AI to correct any spelling and grammatical errors in the text, ensuring it is free of mistakes and reads professionally.' |
| 525 | 547 | ], |
| 526 | 548 | [ |
| 527 | - 'label' => 'Make Shorter', | |
| 549 | + 'label' => __('Make Shorter', 'fluent-support'), | |
| 528 | 550 | 'text' => 'friendly', |
| 529 | 551 | 'description' => 'AI will modify the text to make it shorter and more casual, making it suitable for informal or friendly communication.' |
| 530 | 552 | ], |
| 531 | 553 | [ |
| 532 | - 'label' => 'Make Longer', | |
| 554 | + 'label' => __('Make Longer', 'fluent-support'), | |
| 533 | 555 | 'text' => 'professional', |
| 534 | 556 | 'description' => 'Enhance the text by adding more details and using refined language to make it more formal and detailed, appropriate for professional settings.' |
| 535 | 557 | ], |
| 536 | 558 | [ |
| 537 | - 'label' => 'Simplify Language', | |
| 559 | + 'label' => __('Simplify Language', 'fluent-support'), | |
| 538 | 560 | 'text' => 'simplify', |
| 539 | 561 | 'description' => 'Utilize AI to simplify complex phrases and terminology, making the text easier to read and understand for a general audience.' |
| 540 | 562 | ] |
| 541 | 563 | ]; |
| @@ -546,29 +568,29 @@ | ||
| 546 | 568 | private function getCreateResponsePresets(): array |
| 547 | 569 | { |
| 548 | 570 | $presets = [ |
| 549 | 571 | [ |
| 550 | - 'label' => 'Request More Information', | |
| 572 | + 'label' => __('Request More Information', 'fluent-support'), | |
| 551 | 573 | 'text' => 'requestInfo', |
| 552 | 574 | 'description' => 'Ask the customer to provide additional details or clarification about the issue they reported. This helps in gathering more information to resolve the issue effectively.' |
| 553 | 575 | ], |
| 554 | 576 | [ |
| 555 | - 'label' => 'Acknowledge Issue', | |
| 577 | + 'label' => __('Acknowledge Issue', 'fluent-support'), | |
| 556 | 578 | 'text' => 'acknowledgeIssue', |
| 557 | 579 | 'description' => 'Confirm receipt of the customer\'s issue and reassure them that it is being investigated. This demonstrates that their concern is being taken seriously.' |
| 558 | 580 | ], |
| 559 | 581 | [ |
| 560 | - 'label' => 'Provide Solution', | |
| 582 | + 'label' => __('Provide Solution', 'fluent-support'), | |
| 561 | 583 | 'text' => 'provideSolution', |
| 562 | 584 | 'description' => 'Offer a comprehensive solution or resolution to the problem described by the customer. This should address their concerns and provide actionable steps to resolve the issue.' |
| 563 | 585 | ], |
| 564 | 586 | [ |
| 565 | - 'label' => 'Follow Up', | |
| 587 | + 'label' => __('Follow Up', 'fluent-support'), | |
| 566 | 588 | 'text' => 'followUp', |
| 567 | 589 | 'description' => 'Reach out to the customer after a solution has been provided to ensure that their issue has been resolved to their satisfaction. This helps in confirming the resolution and maintaining good customer relations.' |
| 568 | 590 | ], |
| 569 | 591 | [ |
| 570 | - 'label' => 'Close Ticket', | |
| 592 | + 'label' => __('Close Ticket', 'fluent-support'), | |
| 571 | 593 | 'text' => 'closeTicket', |
| 572 | 594 | 'description' => 'Notify the customer that their ticket will be closed as the issue has been resolved. Ensure that all their concerns are addressed before closing the ticket.' |
| 573 | 595 | ] |
| 574 | 596 | ]; |