# Forward
Users can forward messages to other users or group chats while using Mini Games.
# Forward Menu
Click on the button in the upper right corner, a menu will pop up. The "Forward" option in the menu is not displayed by default. Via wx.showShareMenu() and wx.hideShareMenu(), this option can be dynamically displayed and hidden.
# Passive Forwarding
When the user clicks on the "Forward" option in the upper-right menu, a forward event will be triggered. If the Mini Game subscribes this event via wx.onShareAppMessage(), you can modify the forwarding card's content by returning a customized forwarding parameter, otherwise default content will be used.
wx.onShareAppMessage(function () {
// The user clicked the "Forward" button
return {
title: 'forward title'
}
})
# Active Forwarding
In the game, the forwarding interface can be directly invoked through the wx.shareAppMessage() interface. Similar to passive forwarding, the content of the forwarded card can be customized.
wx.shareAppMessage({
title: 'forward title'
})
# Using Canvas Content as a Forwarding Image
If you do not specify a forwarding picture, a Mini Program's logo is displayed by default. If you want to display the contents of Canvas when forwarding, you can use Canvas.toTempFilePath() or Canvas.toTempFilePathSync() to generate a local image and pass the image path to the imageUrl parameter.
For the forwarded message card, the best display ratio of the image is 5:4.
wx.onShareAppMessage(function () {
return {
title: 'forward title',
imageUrl: canvas.toTempFilePathSync({
destWidth: 500,
destHeight: 400
})
}
})
# withShareTicket Mode
The forwarding properties can be modified via the wx.updateShareMenu interface. If withShareTicket
is set to true
, it will have the following effect
- When selecting a contact, only one target can be selected, multiple selection cannot be supported
- After the message is forwarded, it cannot be forwarded for the second time by being pressed and held in the session window.
- If the goal of message forwarding is a group chat,
- Will get a
shareTicket
when forwarding is successful - Each time the user enters from the message card, he will also get a
shareTicket
, populatingshareTicket
by calling the wx.getShareInfo() interface can get related information of the group
After this attribute is modified, active forwarding and passive forwarding take effect at the same time.
// Set withShareTicket: true
wx.updateShareMenu({
withShareTicket: true
})