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.

46 lines
1.6KB

  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 == "wework":
  32. from channel.wework.wework_channel import WeworkChannel
  33. ch = WeworkChannel()
  34. elif channel_type == const.FEISHU:
  35. from channel.feishu.feishu_channel import FeiShuChanel
  36. ch = FeiShuChanel()
  37. elif channel_type == const.DINGTALK:
  38. from channel.dingtalk.dingtalk_channel import DingTalkChanel
  39. ch = DingTalkChanel()
  40. else:
  41. raise RuntimeError
  42. ch.channel_type = channel_type
  43. return ch