Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

linkai_client.py 1009B

před 1 rokem
12345678910111213141516171819202122232425262728
  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. class ChatClient(LinkAIClient):
  7. def __init__(self, api_key, host, channel):
  8. super().__init__(api_key, host)
  9. self.channel = channel
  10. self.client_type = channel.channel_type
  11. def on_message(self, push_msg: PushMsg):
  12. session_id = push_msg.session_id
  13. msg_content = push_msg.msg_content
  14. logger.info(f"receive msg push, session_id={session_id}, msg_content={msg_content}")
  15. context = Context()
  16. context.type = ContextType.TEXT
  17. context["receiver"] = session_id
  18. context["isgroup"] = push_msg.is_group
  19. self.channel.send(Reply(ReplyType.TEXT, content=msg_content), context)
  20. def start(channel):
  21. client = ChatClient(api_key=conf().get("linkai_api_key"),
  22. host="link-ai.chat", channel=channel)
  23. client.start()