You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

преди 2 години
преди 1 година
преди 2 години
преди 1 година
преди 2 години
преди 2 години
преди 1 година
преди 1 година
преди 1 година
преди 1 година
преди 1 година
преди 1 година
преди 1 година
преди 1 година
12345678910111213141516171819202122232425262728293031323334353637383940
  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)