实现完整的Freshdesk和Freshchat集成支持,包含会话守卫、错误定义、消息去重、配置管理、webhook处理、出站消息发送、状态监控、安全校验、配对功能和流式回复支持
38 lines
1.3 KiB
Python
38 lines
1.3 KiB
Python
import logging
|
|
|
|
from yuxi.channel.extensions.freshdesk.constants import (
|
|
FRESHDESK_BLOCK_STREAMING_CHUNK_MAX_CHARS,
|
|
FRESHDESK_BLOCK_STREAMING_CHUNK_MIN_CHARS,
|
|
)
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class FreshdeskStreaming:
|
|
streaming_mode = "block"
|
|
block_streaming_enabled = True
|
|
block_streaming_chunk_min_chars = FRESHDESK_BLOCK_STREAMING_CHUNK_MIN_CHARS
|
|
block_streaming_chunk_max_chars = FRESHDESK_BLOCK_STREAMING_CHUNK_MAX_CHARS
|
|
block_streaming_break = "\n"
|
|
block_streaming_chunk_break_preference = "paragraph"
|
|
block_streaming_coalesce_defaults = None
|
|
|
|
def create_pipeline(self, outbound, target_id: str, account_id: str | None = None):
|
|
from yuxi.channel.streaming.block import BlockReplyPipeline
|
|
|
|
return BlockReplyPipeline(
|
|
outbound=outbound,
|
|
target_id=target_id,
|
|
account_id=account_id,
|
|
chunk_min_chars=self.block_streaming_chunk_min_chars,
|
|
chunk_max_chars=self.block_streaming_chunk_max_chars,
|
|
break_char=self.block_streaming_break,
|
|
break_preference=self.block_streaming_chunk_break_preference,
|
|
)
|
|
|
|
def create_draft_stream_session(self, target_id: str) -> object:
|
|
return {"target_id": target_id, "content": ""}
|
|
|
|
def create_block_chunker(self) -> object:
|
|
return {"mode": "length"}
|