Work-bot Documentation

website·Indexed 35 days ago

https://wxwork.apifox.cn/

Developer documentation for Work-bot, an automation control robot for WeChat and Enterprise WeChat. It provides open APIs for messaging (text, images, files, video, voice, and mini-programs), contact management, and message receiving and forwarding to help developers build automated applications and system integrations.

Tokens
69.5K
Snippets
300
Records
394
Agent score
49%

What's inside Work-bot

  1. Overview of Work-bot automation capabilities

    Work-bot is an automation software wrapper for the WeChat and Enterprise WeChat apps. It allows developers to programmatically control the apps via an open API to replace manual operations. Key capabilities include receiving event messages, automated responses, sending/receiving system messages, automatic group invitations, and group management. It is typically used to build systems such as aggregated chat workstations, automated lead generation tools, marketing software, community management tools, and AI customer service bots.
  2. Handle New Friend Addition Notifications (robot.contact.modify)

    When a new friend is added, the system sends a POST notification to the configured callback URL. The notification is identified by the command type robot.contact.modify. This event provides detailed information about the added contact, including their user ID, company details, and profile information.
    {
        "type":"robot.contact.modify",
        "flag":2057,
        "robotKey":"0cb507fa35f543c59f9f0ae376217316",
        "bizType":5,
        "robotType":2,
        "os":"win",
        "isSendFromMac":1,
        "code":"0",
        "msg":"OK",
        "sendTime":"2023-04-07 18:19:53",
        "sendTimeTs":1680862793,
        "dts":1680862793901,
        "userId":7881300926912210,
        "markAsCustomerTime":"2023-04-07 11:49:37",
        "avatorUrl":"http://wx.qlogo.cn/mmhead/jJSbu4Te5ib8JiawHnicB8JT0iaKnLZrWZjKwLhu0qHTF4riaRjbsLSbApw/0",
        "corpanyId":1970325134026788,
        "corpName":"微信",
        "corpShortName":"微信",
        "createTime":"1680839374",
        "departmentId":"",
        "departmentName":"",
        "position":"",
        "account":"",
        "job":"",
        "mobile":"",
        "name":"Wik@星吾",
        "realName":"",
        "rtxName":"",
        "realRemarks":"",
        "remarks":"",
        "gender":1,
        "wechatImgUrl":"http://wx.qlogo.cn/mmhead/jJSbu4Te5ib8JiawHnicB8JT0iaKnLZrWZjKwLhu0qHTF4riaRjbsLSbApw/0",
        "phone":"",
        "messageId":"type:add:202304071819537388"
    }
  3. Handle incoming GIF animation messages in WeCom bot

    When a WeCom bot receives a GIF animation message, the system typically sends two separate POST requests to the /XXXX/service/result endpoint.

    1. The first message is of type chat.message and contains general metadata about the sender and conversation, but the emoticonUrl is null.
    2. The second message is of type message.emoticon and contains the actual emoticonUrl pointing to the GIF resource.

    Both messages share common identifiers such as msgSvrID and msgSeq to allow the developer to correlate the two events.

    // First Message: General Notification
    {
    	"type": "chat.message",
    	"contentType": 29,
    	"robotKey": "0d5b56201d0446debd5021a99ac37f44",
    	"msgSvrID": 1199371,
    	"msgSeq": 12068649,
    	"senderId": "7881300926912210",
    	"emoticonUrl": null,
    	"messageId": "202405061521396619:2"
    }
    
    // Second Message: GIF URL Delivery
    {
      "type": "message.emoticon",
      "contentType": 29,
      "robotKey": "bbd4b93912df4dda9ffe3650d22123e4",
      "msgSvrID": 1199371,
      "msgSeq": 12068649,
      "senderId": "7881300926912210",
      "emoticonUrl": "https://wework.qpic.cn/wwpic3az/wwwx_c8483646c88c1833692408b5f5bcf5df/0",
      "messageId": "202405061521371541:1"
    }
  4. Inquire about contact information via WeCom Robot

    Use the /wxworkapi/message/exchange endpoint to inquire about specific contact details. The request must include the command keyword robot.contacts.inquiry in the type field and a list of contact IDs in the contacts array.
    POST /wxworkapi/message/exchange
    {
      "messageId": "20201029140953087689504360",
      "robotKey": "e46ff1f6a2ea4ceca04a82ad209b9dbc",
      "type": "robot.contacts.inquiry",
      "contacts": [
        "7881303487898658"
      ]
    }
  5. Handle robot.members.chain notifications for new group members

    The robot.members.chain event is a callback notification sent to a WeCom (Enterprise WeChat) robot when new members are added to a customer group. The notification provides details about the inviter, the list of invitees, and the specific group conversation context.
    {
        "type": "robot.members.chain",
        "robotKey": "2e308e7566684bd681722c80210c8084",
        "conversationId": "R:10967117861675483",
        "chatroom": "R:10967117861675483",
        "dts": 1726120987862,
        "inviter": {
            "nickName": "周**",
            "groupNickName": "",
            "userId": 1688855175476092,
            "headImg": "https://wework.qpic.cn/wwpic/...",
            "userName": "1688855175476092"
        },
        "invitee": [
            {
                "gender": 1,
                "nickName": "ZHOU",
                "groupNickName": "ZHOU",
                "userId": "7881302515908019",
                "headImg": "http://wx.qlogo.cn/mmhead/...",
                "userName": "7881302515908019"
            }
        ],
        "messageId": "20240912140307826221972711",
        "conversationType": 2,
        "groupNickName": "天上人家-001",
        "robotType": 2,
        "code": "0",
        "inviteType": 0,
        "name": "天上人家-001"
    }
  6. Handle forward message result callbacks

    After requesting a message forward, the system sends a notification to the configured callback interface (e.g., /XXXX/service/result). The callback payload contains the delivery status and metadata about the forwarded message, such as isSendFail, code, and messageId.
    {
        "messageId": "20241017193703173470846198",
        "type": "message.forward",
        "code": "0",
        "msg": "OK",
        "isSendFail": 1,
        "robotKey": "2e308e7566684bd681722c80210c8084",
        "friends": [
            "7881303615907714",
            "1688853471030780"
        ],
        "sendTime": "2024-10-17 19:38:24"
        // ... other metadata fields
    }
  7. Handle group member change notifications (robot.group.member.changed)

    When group members change in a customer group, the system sends a POST request to the configured callback URL. The payload contains details about the group, the time of the event, and the specific users who joined or left the group.
    {
    	"robotKey": "8c493a62a7ef409b9dffca746382cef0",
    	"bizType": 5,
    	"robotType": 2,
    	"os": "winM",
    	"isSendFromMac": 1,
    	"code": "0",
    	"msg": "OK",
    	"conversationId": "R:10882650916486946",
    	"messageId": "202404101154311817:1",
    	"groupNickName": "",
    	"sendTime": "2024-04-10 11:54:36",
    	"sendTimeTs": 1712721276,
    	"dts": 1712721276000,
    	"newMembers": [{
    		"userId": "1688855218535373"
    	}],
    	"quitedUserIds": [],
    	"chatroom": "R:10882650916486946",
    	"type": "robot.group.members.changed"
    }
  8. Process robot.contact.modify group change events

    When a robot.contact.modify event occurs, the payload contains detailed information about the group, including the conversationId, group name, creatorId, and a full memberList containing user details (userId, name, mobile, etc.) and their admin status (isConvAdmin).
    {
        "robotKey":"0cb507fa35f543c59f9f0ae376217316",
        "bizType":5,
        "robotType":2,
        "os":"win",
        "code":"0",
        "msg":"OK",
        "sendTime":"2023-04-07 17:17:15",
        "conversationId":"R:10760444294928670",
        "name":"好好福利群1",
        "creatorId":1688856647353699,
        "memberList":[
            {
                "userId":1688856647353699,
                "isConvAdmin":0,
                "name":"福利酱",
                "mobile":"13534089515"
            },
            {
                "userId":7881303170011009,
                "isConvAdmin":1,
                "name":"烟花易冷"
            }
        ],
        "memberCount":3,
        "convManagers":[
            7881303170011009
        ],
        "type":"contact.modify",
        "messageId":"202304071717151679"
    }
  9. Retrieve Moments details via the Message Exchange API

    Use the /wxworkapi/message/exchange endpoint to retrieve detailed information about specific Moments posts. This is a POST request that requires a specific type of robot.moment.detail to trigger the retrieval of Moments data. You can query up to 10 Moments IDs (sids) in a single request.
    POST /wxworkapi/message/exchange
    {
        "type": "robot.moment.detail",
        "messageId": "2025030202101123456112",
        "sids": [
            "7446708909151244406"
        ],
        "robotKey": "0620cddfeb6a42b9a1a9395e0e869b11"
    }
  10. Handle incoming Red Packet message notifications for WeCom bots

    When a WeCom bot receives a 'Red Packet' (红包) message, the system sends a POST request to the configured service endpoint. The payload contains metadata about the sender, the conversation, and the message itself. Key identifiers include contentType: 26 and bizType: 5, which signify a Red Packet message.
    {
    	"type": "chat.message",
    	"contentType": 26,
    	"msg": "OK",
    	"isSendFromMac": 1,
    	"senderHeadImg": "http://wx.qlogo.cn/mmhead/IbQhd2Y9oKfq2n78gE3dL8Hq7D0P3NPWbYZDIRkJ0EglRnIwHJxPdA/0",
    	"code": 0,
    	"bizType": 5,
    	"chat_user": 7881303615907714,
    	"conversationName": "迷途小书童",
    	"remark": "恭喜发财,大吉大利",
    	"isControlMessage": 0,
    	"content": "红包消息",
    	"msgSvrID": 1005684,
    	"senderId": 7881303615907714,
    	"senderName": "迷途小书童",
    	"isSendFromSelf": 0,
    	"receiverId": 1688858104495211,
    	"msgSeq": 14349461,
    	"realSenderName": "",
    	"iconUrl": "http://dldir1.qq.com/qqcontacts/hongbao1x_20160413.png",
    	"dts": 1710837999061,
    	"clientId": "hongbao_7881303615907714_1800008896202403196416371480014",
    	"os": "android",
    	"conversationId": "S:1688858104495211_7881303615907714",
    	"messageId": "2024031916463900000039",
    	"sendTimeTs": 1710837999,
    	"chatUser": 7881303615907714,
    	"sendTime": "2024-03-19 16:46:39",
    	"robotKey": "aa654861f84345d2bf89cfba36c04bca",
    	"robotType": 2,
    	"cppContentType": 26,
    	"isGroupChat": 0
    }
  11. Handle 'Message Revoked' notifications for WeCom robots

    When a message is revoked by a user, the WeCom robot receives a POST notification at the /XXXX/service/result endpoint. The request body contains details about the revoked message, including the message ID and the sender's information. The type field will be set to robot.message.revoked to identify this event.
    {
    	"type": "robot.message.revoked",
    	"robotKey": "aa654861f84345d2bf89cfba36c04bca",
    	"chatUser": 1688854987563191,
    	"sendTime": "2024-03-21 10:03:01",
    	"sendTimeTs": 1710986581,
    	"content": "该消息已被撤回",
    	"msgSvrID": 1006215,
    	"contentType": 1011,
    	"messageId": "2024032110030100000011"
    }
  12. Process 'robot.contact.modify' group notification payload

    When a robot.contact.modify event occurs (such as creating a new group or changing group details), the callback payload contains detailed information about the group, its creator, and the current member list.
    {
        "robotKey": "0cb507fa35f543c59f9f0ae376217316",
        "bizType": 5,
        "robotType": 2,
        "os": "win",
        "isSendFromMac": 1,
        "code": "0",
        "msg": "OK",
        "sendTime": "2023-04-07 16:52:26",
        "sendTimeTs": 1680857546,
        "dts": 1680857546546,
        "conversationId": "R:10811579219743292",
        "name": "天天抢福福和利利的福利群999",
        "creatorId": 1688856647353699,
        "creatorName": "福利酱",
        "memberList": [
            {
                "userId": 1688856647353699,
                "markAsCustomerTime": "1970-01-01 08:00:00",
                "avatorUrl": "https://wework.qpic.cn/wwpic/484947_dSdDSbpASuucJpG_1654669245/0",
                "corpanyId": 1970326798979095,
                "isConvAdmin": 0,
                "createTime": "1970-01-01 08:00:00",
                "position": "",
                "account": "",
                "job": "",
                "mobile": "13534089515",
                "name": "福利酱",
                "realName": "**",
                "rtxName": "13534089515",
                "realRemarks": "",
                "remarks": "",
                "gender": 2,
                "inviteUserId": 1688856647353699,
                "wechatImgUrl": "https://wework.qpic.cn/wwpic/484947_dSdDSbpASuucJpG_1654669245/0"
            },
            {
                "userId": 7881303170011009,
                "markAsCustomerTime": "2023-04-06 17:24:31",
                "avatorUrl": "http://wx.qlogo.cn/mmhead/Q3auHgzwzM5fqQscWsZwEwSvWKSjO2RSroK7RC3nhGV2uonQHgia2Tw/0",
                "corpanyId": 1970325134026788,
                "isConvAdmin": 0,
                "createTime": "2023-04-06 17:24:28",
                "position": "",
                "account": "",
                "job": "",
                "mobile": "",
                "name": "烟**冷",
                "realName": "",
                "rtxName": "",
                "realRemarks": "",
                "remarks": "",
                "gender": 0,
                "inviteUserId": 1688856647353699,
                "wechatImgUrl": "http://wx.qlogo.cn/mmhead/Q3auHgzwzM5fqQscWsZwEwSvWKSjO2RSroK7RC3nhGV2uonQHgia2Tw/0"
            }
        ],
        "memberCount": 2,
        "convManagers": [],
        "conversationType": 2,
        "type": "contact.modify",
        "messageId": "202304071652264664"
    }