channel_factory.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. """
  2. channel factory
  3. """
  4. from common import const
  5. from .channel import Channel
  6. def create_channel(channel_type) -> Channel:
  7. """
  8. create a channel instance
  9. :param channel_type: channel type code
  10. :return: channel instance
  11. """
  12. ch = Channel()
  13. if channel_type == "wx":
  14. from channel.wechat.wechat_channel import WechatChannel
  15. ch = WechatChannel()
  16. elif channel_type == "wxy":
  17. from channel.wechat.wechaty_channel import WechatyChannel
  18. ch = WechatyChannel()
  19. elif channel_type == "terminal":
  20. from channel.terminal.terminal_channel import TerminalChannel
  21. ch = TerminalChannel()
  22. elif channel_type == "wechatmp":
  23. from channel.wechatmp.wechatmp_channel import WechatMPChannel
  24. ch = WechatMPChannel(passive_reply=True)
  25. elif channel_type == "wechatmp_service":
  26. from channel.wechatmp.wechatmp_channel import WechatMPChannel
  27. ch = WechatMPChannel(passive_reply=False)
  28. elif channel_type == "wechatcom_app":
  29. from channel.wechatcom.wechatcomapp_channel import WechatComAppChannel
  30. ch = WechatComAppChannel()
  31. elif channel_type == "wechatcom_service":
  32. from channel.wechatcs.wechatcomservice_channel import WechatComServiceChannel
  33. ch = WechatComServiceChannel()
  34. elif channel_type == "wework":
  35. from channel.wework.wework_channel import WeworkChannel
  36. ch = WeworkChannel()
  37. elif channel_type == const.FEISHU:
  38. from channel.feishu.feishu_channel import FeiShuChanel
  39. ch = FeiShuChanel()
  40. elif channel_type == const.DINGTALK:
  41. from channel.dingtalk.dingtalk_channel import DingTalkChanel
  42. ch = DingTalkChanel()
  43. elif channel_type == "gewechat":
  44. from channel.gewechat.gewechat_channel import GeWeChatChannel
  45. ch = GeWeChatChannel()
  46. else:
  47. raise RuntimeError
  48. ch.channel_type = channel_type
  49. return ch