# Weixin Mini Program Liaotiantool Pattern Development Guide Beta

# I. Function introduction

Chat Tool Mode is a mode introduced to help Weixin Mini Program better integrate with WeChat chat, and can be used to implement functions such as group questionnaires, group forms, and group tasks. Its ability to open up more closely to chat than the ordinary mode of Mini Programs:

  1. Chat member correlation capability: developers can call chat member selector and get member correlation id, rendering chat member avatar nickname through open data field
  2. The ability to send content to chat: Developers can send text, reminders, pictures, emojis, videos and other content types to chat
  3. Dynamic message capability: Weixin Mini Program Subtitles on the card can be dynamically updated to send system messages after the user completes / participates in the activity

At the same time, Liaotiantool mode needs to use independent subcontract based on Skyline development, the subcontract can also be opened by ordinary mode.Developers can experience the Demo launched by the platform through the "Weixin Mini Program sample - interface Tab- Liaotiantool" entrance:

# II. Development Guide

3.7.8

Supported platform: Android: WeChat 8.0.56 and above , iOS: WeChat 8.0.56 and above

# 1. Chat tool sub-package configuration

Developers need to declare Weixin Mini Program global configuration (apagejson) insubpackagesand [[TAG-1- END]]chatTools

  1. The subPackagesis the basic configuration of the subpackage, the attribute explaination can refer to the configuration of the subpackage structure
  2. Chattoolsis configured for chatTools with typeObject []and fields include:
attribute type Required to fill in Introductions
root string yes Subpackage root directory
entryPagePath string yes Chat tool startup path
desc string yes Description of a chat tool
scopes string[] no scope permissions that will be used in sub-packageing

Notes :

  1. Descshould be filled in according to your own functional design.scopesPlease fill in the fields truthfully;Otherwise, it will affect the result of Weixin Mini Program audit
  2. Developers need to ensure that the path to the home page of the subcontract can be used after entering the complete function of Liaotian tools, otherwise it will affect the results of Weixin Mini Program audit
  3. Each Weixin Mini Program currently only supports the configuration of a chat tool, the subsequent may release
  4. The volume of the subcontract of Liaotiantool shall not exceed 500KB
  5. WeChat will prompt an error when previewing / uploading code packages if the developer has not configured them.

Example configuration:

{
  "subPackages": [
    {
      "root": "packageA",
      "name": "alias",
      "pages": ["pages/cat"],
      "independent": true,
      "entry": "index.js",
      "componentFramework": "glass-easel",
      "renderer": "skyline",
    },
  ],
  "chatTools": [{
    "root": "packageA",
    "entryPagePath": "x",
    "desc": "功能描述",
    "scopes": ["scope.userLocation"]
  }],
  "rendererOptions": {
    "skyline": {
      "disableABTest": true,
      "defaultDisplayBlock": true,
      "defaultContentBox": true,
      "tagNameStyleIsolation": "legacy",
      "sdkVersionBegin": "3.7.0",
      "sdkVersionEnd": "15.255.255"
    }
  }
}

# 2. Entering and exiting chat tool mode

# 2.1 Enter chat mode

Liaotiantool mode needs to bind a single chat or group chat Liaotianroom when entering, there are three ways to enter:

  1. When Weixin Mini Program is in normal mode, the developer invokes wx.openChatTool But not incoming Liaotianshi id, WeChat will pull up the chat list for the user to choose, the user selected binding Liaotianshi into Liaotiantool mode
  2. When Weixin Mini Program is in normal mode, the developer invokes wx.openChatTool And pass in the interface Liaotianroom id (group chat is opengid, single chat is open_single_roomid), will directly bind the Liaotianroom into the
  3. After a user sends various types of content to a bound chat in chat tool mode, when the user returns to Weixin Mini Program from these content entry points in the same chat, the chat is opened in chat tool Mode, and the bound chat remains unchanged.

# 2.2 Exit chat mode

Chat tools currently have three ways to opt out:

  1. Back in a chat tool to a non-chat tool subpackage page (including user-initiated returns, developer calls [[)wx.navigateBack/wx.switchTab), will trigger the exit of Chat Tools mode
  2. Weixin Mini Program reLaunch to a normal page (including users clicking on other non-chat tool mode entrances, developers callingwx.reLaunchetc.) triggers exit from chat tool mode

Note: On a chat tool subpackage page, you cannot skip to a non-chat tool subpackage bywx.navigateToorwX.redirectTo.If you need to jump, first through thewx.navigateBackexit the current Liaotiantool subcontract, use the routing interface to jump.

# 2.3 Determining the mode of a chat tool

Developers may use wx.getApiCategory Whether theapiCategoryfield inchatTool,Determine whether you are currently in chat tool mode.

# 3.1 Get the correlation id interface

There are three types of ID information in Liaotiantool mode:

  1. Opengid: WeChat group unique identifier id
  2. Open_single_roomid: unique identifier id for a single chat
  3. Group_openid: WeChat The unique identifier of a user under this Liaotianroom, the same user under different Liaotianroom id is different

The related interface is as follows:

  1. Wx.getgroupenterinfo : Get group chat id information before entering the chat mode
  2. Wx.getchattoolinfo : Get the group chat id information when you enter the chat mode

The difference between the two interfaces is that in the Liaotiantool subcontract page, it is recommended to usewx.getChatToolInfoto get information about the binding group.Before entering the chat tool subpackage page, for example, open Weixin Mini Program from the group chat session card. At this point, you want to reuse the group chat in which the card is located, bywx.getGroupEnterInfoto obtain thegroup of the card opengid, And inwx.openChatTool`, at this time you can not call up the group selection list, directly into.

# 3.2 Select the chat member interface

The developer can call wx.selectGroupMembers to let the user select a member of Liaotianroom and return the group_openid of the selected member.It should be noted that if the current chat room for a single chat, then directly return to the other user's group_openid, no longer pull up the selector.

# 3.3 Render avatar nicknames of chat members

Developers may contact open-data-list with open-data-item Render chat member avatar nickname

# 4. Send to chat capability

You can send Weixin Mini Program cards, reminder messages, text, pictures, emoticons, files to the chat, the relevant interface is as follows:

  1. Wx.shareAppMessageToGroup : Send Weixin Mini Program card to the bound Liaotianroom
  2. wx.notifyGroupMembers :Remind the user to complete the task. The content sent will be spelled by WeChat as: member list of @ + "Please complete:" / "Please participate:"+ open the Weixin Mini Program text chain, such as "@ alex @cindy Please complete: group registration statistics"
  3. Form bind: submitToGroup = "onSubmitToGroup" with button form-type="submitToGroup" :Send text content from the input box to the bound chat room
  4. Wx.shareImageToGroup : Send pictures to bound Liaotianroom
  5. Wx.shareEmojiToGroup : Send the emoji to the bound Liaotianroom
  6. Wx.shareVideoToGroup : Send video to bound Liaotianroom
  7. Wx.shareFileToGroup : Send files to bound Liaotianroom

# 5. Dynamic Messaging Capabilities

From a Weixin Mini Program card sent in chat mode, the dynamic messaging capability can be obtained. User representations of this capability include:

  1. Weixin Mini Program Subtitles on cards can be dynamically updated
  2. You can post a system message in a chat that reads: member A + "completed" / "participated" + member B + "posted" + open the Weixin Mini Program text chain, such as, "alex completed the group membership statistics posted by cindy"

The development steps for this feature include:

# 5.1 创建activity_id

Create an activity_id interface with

# 5.2 Declare sharing card as a dynamic message

Front end via wx.updateShareMenu Declare the card to be shared as a dynamic message and request the following parameters:

NOTE:

  1. When useForChatToolistrue,chooseTypeandparticipantonly take effect
  2. ChooseType= 1, indicating that the participant`is treated as a participant as specified
  3. ChooseType= 2, indicating that all members of the group are participants (including after joining the group)

Code example:

wx.updateShareMenu({
        withShareTicket: true,
        isUpdatableMessage: true,
        activityId: 'xxx',
        useForChatTool: true,
        chooseType: 1,
        participant: that.data.members,
        templateInfo: {
          templateId:    '4A68CBB88A92B0A9311848DBA1E94A199B166463'
        },
)

Template differences (target_state and participator_state meaning see step 3):

templateId 4A68CBB88A92B0A9311848DBA1E94A199B166463 2A84254B945674A2F88CE4970782C402795EB607
Subheadings seen by the news publisher in the Weixin Mini Program card Target_state = 1 or 2: X people have completed;Target_state = 3: Closed Target_state = 1 or 2: X people have participated;Target_state = 3: Closed
Subtitles that participants see in Weixin Mini Program cards Participator_state = 0: target_state = 1: unfinished, target_state = 2: coming to an end, target_state = 3: finished;When participator_state = 1: target_state = 1 or 2: completed, target_state = 3: completed. When participator_state = 0: target_state = 1: not participating, target_state = 2: closing soon, target_state = 3: closed;When participator_state = 1: target_state = 1 or 2: participated, target_state = 3: ended.
Subtitles seen by non-participants in Weixin Mini Program cards Target_state = 1 or 2: You don't have to finish;Target_state = 3: Closed Target_state = 1 or 2: You don't need to participate;Target_state = 3: Closed
The participant becomes complete and sends the system message copy Aaa has completed the XXX released by bbb Aaa has participated in the XXX released by bbb

# 5.3 Update activity status or user completion status

The server updates activity status or user completion via the setChatToolMsg interface.

Also called via cloud development, interface namechattoolmsg.send.

Example call:

//变更单个成员状态
{
    "activity_id": "xxx",
    "target_state":1,
    "version_type": 0,
    "participator_info_list": [
        {
            "group_openid": "aaa",
            "state": 1
        },
        {
            "group_openid": "bbb",
            "state": 1

        }
    ]
}
//变更动态消息状态
{
    "activity_id": "xxx",
    "target_state":3,
    "version_type": 0,
}

# 6. The ability to disable it in chat tool mode

The following capabilities are not currently supported in chat tool mode, so developers are advised to adapt them.

  1. The chat tool mode disables the normal forwarding capability. Use the interface in "Send to chat capability open" above to implement this:button open-type = shareand Weixin Mini Program top right corner... "- Send to a friend "
  2. In Weixin Mini Program, the external jump class interface does not support the use of:
    • navigateToMiniProgram;
    • openEmbeddedMiniProgram;
    • openOfficialAccountArticle;
    • openChannelsUserProfile;
    • openChannelsLive;
    • openChannelsEvent;
    • openChannelsActivity。
  3. adandad-custom