Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

41 lines
1.1KB

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