message.go 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. package syncmsg
  2. // BaseMessage 接收消息
  3. type BaseMessage struct {
  4. MsgID string `json:"msgid"` // 消息ID
  5. OpenKFID string `json:"open_kfid"` // 客服帐号ID(msgtype为event,该字段不返回)
  6. ExternalUserID string `json:"external_userid"` // 客户UserID(msgtype为event,该字段不返回)
  7. ReceptionistUserID string `json:"servicer_userid"` // 接待客服userID
  8. SendTime uint64 `json:"send_time"` // 消息发送时间
  9. Origin uint32 `json:"origin"` // 消息来源。3-微信客户发送的消息 4-系统推送的事件消息 5-接待人员在企业微信客户端发送的消息
  10. }
  11. // Text 文本消息
  12. type Text struct {
  13. BaseMessage
  14. MsgType string `json:"msgtype"` // 消息类型,此时固定为:text
  15. Text struct {
  16. Content string `json:"content"` // 文本内容
  17. MenuID string `json:"menu_id"` // 客户点击菜单消息,触发的回复消息中附带的菜单ID
  18. } `json:"text"` // 文本消息
  19. }
  20. // Image 图片消息
  21. type Image struct {
  22. BaseMessage
  23. MsgType string `json:"msgtype"` // 消息类型,此时固定为:image
  24. Image struct {
  25. MediaID string `json:"media_id"` // 图片文件ID
  26. } `json:"image"` // 图片消息
  27. }
  28. // Voice 语音消息
  29. type Voice struct {
  30. BaseMessage
  31. MsgType string `json:"msgtype"` // 消息类型,此时固定为:voice
  32. Voice struct {
  33. MediaID string `json:"media_id"` // 语音文件ID
  34. } `json:"voice"` // 语音消息
  35. }
  36. // Video 视频消息
  37. type Video struct {
  38. BaseMessage
  39. MsgType string `json:"msgtype"` // 消息类型,此时固定为:video
  40. Video struct {
  41. MediaID string `json:"media_id"` // 文件ID
  42. } `json:"video"` // 视频消息
  43. }
  44. // File 文件消息
  45. type File struct {
  46. BaseMessage
  47. MsgType string `json:"msgtype"` // 消息类型,此时固定为:file
  48. File struct {
  49. MediaID string `json:"media_id"` // 文件ID
  50. } `json:"file"` // 文件消息
  51. }
  52. // Location 地理位置消息
  53. type Location struct {
  54. BaseMessage
  55. MsgType string `json:"msgtype"` // 消息类型,此时固定为:location
  56. Location struct {
  57. Latitude float32 `json:"latitude"` // 纬度
  58. Longitude float32 `json:"longitude"` // 经度
  59. Name string `json:"name"` // 位置名
  60. Address string `json:"address"` // 地址详情说明
  61. } `json:"location"` // 地理位置消息
  62. }
  63. // Link 链接消息
  64. type Link struct {
  65. BaseMessage
  66. MsgType string `json:"msgtype"` // 消息类型,此时固定为:link
  67. Link struct {
  68. Title string `json:"title"` // 标题
  69. Desc string `json:"desc"` // 描述
  70. URL string `json:"url"` // 点击后跳转的链接
  71. PicURL string `json:"pic_url"` // 缩略图链接
  72. } `json:"link"` // 链接消息
  73. }
  74. // BusinessCard 名片消息
  75. type BusinessCard struct {
  76. BaseMessage
  77. MsgType string `json:"msgtype"` // 消息类型,此时固定为:business_card
  78. BusinessCard struct {
  79. UserID string `json:"userid"` // 名片 userid
  80. } `json:"business_card"` // 名片消息
  81. }
  82. // MiniProgram 小程序消息
  83. type MiniProgram struct {
  84. BaseMessage
  85. MsgType string `json:"msgtype"` // 消息类型,此时固定为:miniprogram
  86. MiniProgram struct {
  87. AppID string `json:"appid"` // 小程序appid,必须是关联到企业的小程序应用
  88. Title string `json:"title"` // 小程序消息标题,最多64个字节,超过会自动截断
  89. ThumbMediaID string `json:"thumb_media_id"` // 小程序消息封面的mediaid,封面图建议尺寸为520*416
  90. PagePath string `json:"pagepath"` // 点击消息卡片后进入的小程序页面路径
  91. } `json:"miniprogram"` // 小程序消息
  92. }
  93. // EventMessage 事件消息
  94. type EventMessage struct {
  95. BaseMessage
  96. MsgType string `json:"msgtype"` // 消息类型,此时固定为:event
  97. Event struct {
  98. EventType string `json:"event_type"` // 事件类型
  99. } `json:"event"` // 事件消息
  100. }
  101. // EnterSessionEvent 用户进入会话事件
  102. type EnterSessionEvent struct {
  103. BaseMessage
  104. MsgType string `json:"msgtype"` // 消息类型,此时固定为:event
  105. Event struct {
  106. EventType string `json:"event_type"` // 事件类型。此处固定为:enter_session
  107. OpenKFID string `json:"open_kfid"` // 客服账号ID
  108. ExternalUserID string `json:"external_userid"` // 客户UserID
  109. Scene string `json:"scene"` // 进入会话的场景值,获取客服帐号链接开发者自定义的场景值
  110. SceneParam string `json:"scene_param"` // 进入会话的自定义参数,获取客服帐号链接返回的url,开发者按规范拼接的scene_param参数
  111. WelcomeCode string `json:"welcome_code"` // 如果满足发送欢迎语条件(条件为:1. 企业没有在管理端配置了原生欢迎语;2. 用户在过去48小时里未收过欢迎语,且未向该用户发过消息),会返回该字段。可用该welcome_code调用发送事件响应消息接口给客户发送欢迎语。
  112. } `json:"event"` // 事件消息
  113. }
  114. // MsgSendFailEvent 消息发送失败事件
  115. type MsgSendFailEvent struct {
  116. BaseMessage
  117. MsgType string `json:"msgtype"` // 消息类型,此时固定为:event
  118. Event struct {
  119. EventType string `json:"event_type"` // 事件类型。此处固定为:msg_send_fail
  120. OpenKFID string `json:"open_kfid"` // 客服账号ID
  121. ExternalUserID string `json:"external_userid"` // 客户UserID
  122. FailMsgID string `json:"fail_msgid"` // 发送失败的消息msgid
  123. FailType uint32 `json:"fail_type"` // 失败类型。0-未知原因 1-客服账号已删除 2-应用已关闭 4-会话已过期,超过48小时 5-会话已关闭 6-超过5条限制 7-未绑定视频号 8-主体未验证 9-未绑定视频号且主体未验证 10-用户拒收
  124. } `json:"event"` // 事件消息
  125. }
  126. // ReceptionistStatusChangeEvent 客服人员接待状态变更事件
  127. type ReceptionistStatusChangeEvent struct {
  128. BaseMessage
  129. MsgType string `json:"msgtype"` // 消息类型,此时固定为:event
  130. Event struct {
  131. EventType string `json:"event_type"` // 事件类型。此处固定为:servicer_status_change
  132. ReceptionistUserID string `json:"servicer_userid"` // 客服人员userid
  133. Status uint32 `json:"status"` // 状态类型。1-接待中 2-停止接待
  134. } `json:"event"`
  135. }
  136. // SessionStatusChangeEvent 会话状态变更事件
  137. type SessionStatusChangeEvent struct {
  138. BaseMessage
  139. MsgType string `json:"msgtype"` // 消息类型,此时固定为:event
  140. Event struct {
  141. EventType string `json:"event_type"` // 事件类型。此处固定为:session_status_change
  142. OpenKFID string `json:"open_kfid"` // 客服账号ID
  143. ExternalUserID string `json:"external_userid"` // 客户UserID
  144. ChangeType uint32 `json:"change_type"` // 变更类型。1-从接待池接入会话 2-转接会话 3-结束会话
  145. OldReceptionistUserID string `json:"old_servicer_userid"` // 老的客服人员userid。仅change_type为2和3有值
  146. NewReceptionistUserID string `json:"new_servicer_userid"` // 新的客服人员userid。仅change_type为1和2有值
  147. MsgCode string `json:"msg_code"` // 用于发送事件响应消息的code,仅change_type为1和3时,会返回该字段。可用该msg_code调用发送事件响应消息接口给客户发送回复语或结束语。
  148. } `json:"event"` // 事件消息
  149. }