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.

45 line
1.5KB

  1. from bridge.context import ContextType
  2. from channel.chat_message import ChatMessage
  3. import json
  4. import requests
  5. from common.log import logger
  6. from common.tmp_dir import TmpDir
  7. from common import utils
  8. from dingtalk_stream import ChatbotMessage
  9. class DingTalkMessage(ChatMessage):
  10. def __init__(self, event: ChatbotMessage):
  11. super().__init__(event)
  12. self.msg_id = event.message_id
  13. msg_type = event.message_type
  14. self.incoming_message =event
  15. self.sender_staff_id = event.sender_staff_id
  16. self.other_user_id = event.conversation_id
  17. self.create_time = event.create_at
  18. if event.conversation_type=="1":
  19. self.is_group = False
  20. else:
  21. self.is_group = True
  22. if msg_type == "text":
  23. self.ctype = ContextType.TEXT
  24. self.content = event.text.content.strip()
  25. elif msg_type == "audio":
  26. # 钉钉支持直接识别语音,所以此处将直接提取文字,当文字处理
  27. self.content = event.extensions['content']['recognition'].strip()
  28. self.ctype = ContextType.TEXT
  29. if self.is_group:
  30. self.from_user_id = event.conversation_id
  31. self.actual_user_id = event.sender_id
  32. else:
  33. self.from_user_id = event.sender_id
  34. self.to_user_id = event.chatbot_user_id
  35. self.other_user_nickname = event.conversation_title
  36. user_id = event.sender_id
  37. nickname =event.sender_nick