← All changes
|
app/Services/Integrations/FluentBot/FluentBotHelper.php
+22
-0
2.3.2
→
2.4.0
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 | |