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ů.

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