Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

31 lignes
1.0KB

  1. from bridge.context import Context, ContextType
  2. from bridge.reply import Reply, ReplyType
  3. from common.log import logger
  4. from linkai import LinkAIClient, PushMsg
  5. from config import conf
  6. chat_client: LinkAIClient
  7. class ChatClient(LinkAIClient):
  8. def __init__(self, api_key, host, channel):
  9. super().__init__(api_key, host)
  10. self.channel = channel
  11. self.client_type = channel.channel_type
  12. def on_message(self, push_msg: PushMsg):
  13. session_id = push_msg.session_id
  14. msg_content = push_msg.msg_content
  15. logger.info(f"receive msg push, session_id={session_id}, msg_content={msg_content}")
  16. context = Context()
  17. context.type = ContextType.TEXT
  18. context["receiver"] = session_id
  19. context["isgroup"] = push_msg.is_group
  20. self.channel.send(Reply(ReplyType.TEXT, content=msg_content), context)
  21. def start(channel):
  22. global chat_client
  23. chat_client = ChatClient(api_key=conf().get("linkai_api_key"),
  24. host="link-ai.chat", channel=channel)
  25. chat_client.start()