Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

45 lines
1.2KB

  1. """
  2. Message sending channel abstract class
  3. """
  4. from bridge.bridge import Bridge
  5. from bridge.context import Context
  6. from bridge.reply import *
  7. class Channel(object):
  8. channel_type = ""
  9. NOT_SUPPORT_REPLYTYPE = [ReplyType.VOICE, ReplyType.IMAGE]
  10. def startup(self):
  11. """
  12. init channel
  13. """
  14. raise NotImplementedError
  15. def handle_text(self, msg):
  16. """
  17. process received msg
  18. :param msg: message object
  19. """
  20. raise NotImplementedError
  21. # 统一的发送函数,每个Channel自行实现,根据reply的type字段发送不同类型的消息
  22. def send(self, reply: Reply, context: Context):
  23. """
  24. send message to user
  25. :param msg: message content
  26. :param receiver: receiver channel account
  27. :return:
  28. """
  29. raise NotImplementedError
  30. def build_reply_content(self, query, context: Context = None) -> Reply:
  31. return Bridge().fetch_reply_content(query, context)
  32. def build_voice_to_text(self, voice_file) -> Reply:
  33. return Bridge().fetch_voice_to_text(voice_file)
  34. def build_text_to_voice(self, text) -> Reply:
  35. return Bridge().fetch_text_to_voice(text)