Loading...
Loading...
WeChat Mini Program Chat Tool Development Guide. Used for developing chat tool subpackages, configuring chatTools, sending messages to group chats, dynamic messages, obtaining group member information, wx.openChatTool, wx.getChatToolInfo.
npx skill4agent add dafang/taro-weapp-plugin wechat-chat-tool{
"subPackages": [
{
"root": "packageChatTool",
"pages": ["pages/entry/index"],
"entry": "entry.js", // Independent subpackage entry file (required)
"independent": true,
"componentFramework": "glass-easel",
"renderer": "skyline"
}
],
"chatTools": [{
"root": "packageChatTool",
"entryPagePath": "pages/entry/index",
"desc": "Function Description",
"scopes": []
}],
"rendererOptions": {
"skyline": {
"disableABTest": true,
"defaultDisplayBlock": true,
"defaultContentBox": true
}
}
}entry.js// Independent subpackage entry file
// Used for initialization in chat tool mode
const enterOptions = wx.getEnterOptionsSync()
console.log('[ChatTool Entry] Enter options:', enterOptions)| API | Purpose |
|---|---|
| Open chat tool mode (can pass opengid or open_single_roomid) |
| Determine if in chat tool mode (apiCategory === 'chatTool') |
| Exit chat tool mode |
| API | Purpose |
|---|---|
| Obtain bound group chat information within chat tool subpackage |
| Obtain group chat id information before entering |
| Select chat room members, return group_openid |
opengidopen_single_roomidgroup_openid| API | Purpose |
|---|---|
| Send Mini Program card |
| Send reminder messages (@members + tasks) |
| Send images |
| Send videos |
| Send files |
| Send emojis |
activity_idwx.updateShareMenusetChatToolMsgwx.updateShareMenu({
withShareTicket: true,
isUpdatableMessage: true,
activityId: "xxx",
useForChatTool: true,
chooseType: 1, // 1=specified members, 2=all members
participant: members,
templateInfo: {
templateId: "4A68CBB88A92B0A9311848DBA1E94A199B166463", // Completion type
// or '2A84254B945674A2F88CE4970782C402795EB607' Participation type
},
});| Property | Type | Default Value | Required | Description |
|---|---|---|---|---|
| url | string | Yes | Page path within the chat tool subpackage | |
| roomid | string | No | Chat room id, if not passed, group selection box will pop up; can pass opengid of multi-person group chat or open_single_roomid of one-on-one chat | |
| chatType | number | No | Group chat type | |
| success | function | No | Callback function for successful interface call | |
| fail | function | No | Callback function for failed interface call | |
| complete | function | No | Callback function for interface call completion (executed on both success and failure) |
| Value | Description |
|---|---|
| 1 | WeChat contact one-on-one chat |
| 2 | WeChat Work contact one-on-one chat |
| 3 | Ordinary WeChat group chat |
| 4 | WeChat Work interoperable group chat |
wx.openChatTool({
url: "pages/chat/index", // Example path
chatType: 1, // WeChat contact one-on-one chat
success(res) {
console.log("Open chat tool successfully", res);
},
fail(err) {
console.error("Failed to open chat tool", err);
},
});Supported since Base Library 2.22.1, need to do compatibility handling for lower versions.
| Value | Description |
|---|---|
| default | Default category |
| nativeFunctionalized | Native functionalization, Mini Programs opened in scenarios like Video号 live goods, product showcase, etc |
| browseOnly | Browse only, Mini Programs opened in scenarios like Moments snapshot pages |
| embedded | Embedded, Mini Programs opened via half-screen Mini Program capability |
| chatTool | Mini Program opened via chat tool |
const apiCategory = wx.getApiCategory();
console.log(apiCategory);Supported since Base Library 3.7.12, need to do compatibility handling for lower versions.
| Property | Type | Default Value | Required | Description |
|---|---|---|---|---|
| title | string | Yes | Forwarding title | |
| path | string | Current page | No | Forwarding path, must be a complete path starting with /, defaults to current page |
| imageUrl | string | Screenshot | No | Custom image path, supports PNG and JPG; aspect ratio of displayed image is 5:4, defaults to screenshot |
| success | function | No | Callback function for successful interface call | |
| fail | function | No | Callback function for failed interface call | |
| complete | function | No | Callback function for interface call completion (executed on both success and failure) |
wx.shareAppMessageToGroup({
title: "Share Title",
path: "/path/to/page",
imageUrl: "",
});| Property | Type | Default Value | Required | Description |
|---|---|---|---|---|
| videoPath | string | Yes | Path of the video to share, must be local or temporary path | |
| thumbPath | string | No | Thumbnail path; if left blank, the first frame of the video will be used | |
| needShowEntrance | boolean | true | No | Whether to show Mini Program entrance in the shared image message |
| entrancePath | string | '' | No | Path to open Mini Program from message entrance, defaults to chat tool startup path |
| success | function | No | Callback function for successful interface call | |
| fail | function | No | Callback function for failed interface call | |
| complete | function | No | Callback function for interface call completion (executed on both success and failure) |
wx.shareVideoToGroup({
videoPath: "path/to/video.mp4",
thumbPath: "path/to/thumb.png",
needShowEntrance: true,
success(res) {
console.log("Share video successfully", res);
},
fail(err) {
console.error("Failed to share video", err);
},
});| Property | Type | Default Value | Required | Description |
|---|---|---|---|---|
| imagePath | string | Yes | Path of the image to share, must be local or temporary path | |
| needShowEntrance | boolean | true | No | Whether to show Mini Program entrance in the shared image message |
| entrancePath | string | '' | No | Path to open Mini Program from message entrance, defaults to chat tool startup path |
| success | function | No | Callback function for successful interface call | |
| fail | function | No | Callback function for failed interface call | |
| complete | function | No | Callback function for interface call completion (executed on both success and failure) |
wx.shareImageToGroup({
imagePath: "path/to/image.png",
needShowEntrance: true,
success(res) {
console.log("Share image successfully", res);
},
fail(err) {
console.error("Failed to share image", err);
},
});| Property | Type | Default Value | Required | Description |
|---|---|---|---|---|
| imagePath | string | Yes | Path of the emoji to share, must be local or temporary path | |
| needShowEntrance | boolean | true | No | Whether to show Mini Program entrance in the shared emoji message |
| entrancePath | string | '' | No | Path to open Mini Program from message entrance, defaults to chat tool startup path |
| success | function | No | Callback function for successful interface call | |
| fail | function | No | Callback function for failed interface call | |
| complete | function | No | Callback function for interface call completion (executed on both success and failure) |
wx.shareEmojiToGroup({
imagePath: "path/to/image.png",
needShowEntrance: true,
success(res) {
console.log("Share emoji successfully", res);
},
fail(err) {
console.error("Failed to share emoji", err);
},
});| Property | Type | Default Value | Required | Description |
|---|---|---|---|---|
| maxSelectCount | number | No | Maximum number of selectable members | |
| success | function | No | Callback function for successful interface call | |
| fail | function | No | Callback function for failed interface call | |
| complete | function | No | Callback function for interface call completion (executed on both success and failure) |
| Property | Type | Description |
|---|---|---|
| members | Array.<string> | Unique identifiers of selected users in this chat room; the same user has different ids in different chat rooms |
wx.selectGroupMembers({
maxSelectCount: 10,
success(res) {
console.log("Select members successfully", res.members);
},
fail(err) {
console.error("Failed to select members", err);
},
});| Property | Type | Default Value | Required | Description |
|---|---|---|---|---|
| title | string | Yes | Text link title; the sent content will be spliced by WeChat as: @mentioned members + "Please complete:"/"Please participate:" + text link to open Mini Program, e.g.「@alex @cindy Please complete: Team Building Registration Statistics」。 | |
| members | Array.<string> | Yes | List of group_openid of users to be reminded | |
| entrancePath | string | Yes | Text link jump path | |
| type | string | complete | No | Displayed verb |
| success | function | No | Callback function for successful interface call | |
| fail | function | No | Callback function for failed interface call | |
| complete | function | No | Callback function for interface call completion (executed on both success and failure) |
| Value | Description |
|---|---|
| participate | Please participate |
| complete | Please complete |
wx.notifyGroupMembers({
title: "Team Building Registration Statistics",
members: ["openid1", "openid2"],
entrancePath: "/pages/index/index",
type: "complete",
success(res) {
console.log("Notify successfully", res);
},
fail(err) {
console.error("Failed to notify", err);
},
});