If I aways use the service api, how do I set the top conversation #5974
Replies: 1 comment
-
Hey there, @lzxtest112233! I'm here to help you with any bugs, questions, or contributions you have regarding the project. Feel free to ask me anything while waiting for a human maintainer. To set the top conversation using the service API, you can use the @classmethod
def pin(cls, app_model: App, conversation_id: str, user: Optional[Union[Account, EndUser]]):
pinned_conversation = db.session.query(PinnedConversation).filter(
PinnedConversation.app_id == app_model.id,
PinnedConversation.conversation_id == conversation_id,
PinnedConversation.created_by_role == ('account' if isinstance(user, Account) else 'end_user'),
PinnedConversation.created_by == user.id
).first()
if pinned_conversation:
return
conversation = ConversationService.get_conversation(
app_model=app_model,
conversation_id=conversation_id,
user=user
)
pinned_conversation = PinnedConversation(
app_id=app_model.id,
conversation_id=conversation.id,
created_by_role='account' if isinstance(user, Account) else 'end_user',
created_by=user.id
)
db.session.add(pinned_conversation)
db.session.commit() To use this method, call Additionally, you can use the class ConversationPinApi(InstalledAppResource):
def patch(self, installed_app, c_id):
app_model = installed_app.app
app_mode = AppMode.value_of(app_model.mode)
if app_mode not in [AppMode.CHAT, AppMode.AGENT_CHAT, AppMode.ADVANCED_CHAT]:
raise NotChatAppError()
conversation_id = str(c_id)
try:
WebConversationService.pin(app_model, conversation_id, current_user)
except ConversationNotExistsError:
raise NotFound("Conversation Not Exists.")
return {"result": "success"} You can call this endpoint to pin a conversation by sending a PATCH request to class ConversationUnPinApi(InstalledAppResource):
def patch(self, installed_app, c_id):
app_model = installed_app.app
app_mode = AppMode.value_of(app_model.mode)
if app_mode not in [AppMode.CHAT, AppMode.AGENT_CHAT, AppMode.ADVANCED_CHAT]:
raise NotChatAppError()
conversation_id = str(c_id)
WebConversationService.unpin(app_model, conversation_id, current_user)
return {"result": "success"} You can call this endpoint to unpin a conversation by sending a PATCH request to |
Beta Was this translation helpful? Give feedback.
-
for example, the web api :
/api/conversations/1633add8-68c1-46b6-8bde-e2f52373ce66/pin
/api/conversations/1633add8-68c1-46b6-8bde-e2f52373ce66/unpin
Beta Was this translation helpful? Give feedback.
All reactions