# Share gadget

You can share the gadget to groups or individuals through the sharing function of the gadget, and the sharers can quickly open and use the gadget through the gadget card. This article mainly introduces how to share gadget to Feishu sessions.

## prerequisites

- The sharing function of the gadget needs to ensure that the Feishu client meets the following version range.
- Mobile terminal: Feishu v2.9 and above.
- Desktop: Feishu v3.11 and above.

- Before calling the sharing function of the gadget, you need to ensure that you have successfully logged in to the gadget by calling the [login](https://open.feishu.cn/document/uYjL24iN/uYzMuYzMuYzM) API.

## Function to realize sharing function

The onShareAppMessage function is included in the gadget page function. Through this function, you can specify the shared title, jump link and preview image, and finally share it in the form of a card to Feishu groups or individuals. For the introduction and field description of the function, please refer to [Configuration Page Sharing](https://open.feishu.cn/document/uYjL24iN/uQDNuQDNuQDN#75f3c5ca).

- By default, the shared gadget uses the upper half of the current screenshot as the preview image, and you can also set a custom preview image through the imageUrl parameter.
- If the onShareAppMessage function is not configured, the share button will not appear on the current page.
After configuring the onShareAppMessage function, in addition to realizing the sharing function, a forward button will also be displayed in the menu at the upper right corner of the gadget.

The sample code configuration of the onShareAppMessage function is as follows:

```js
Page({
     onShareAppMessage: function (opt) {
         console. log(opt);
         return {
             title: opt.from === 'button' ? 'Button Share' : 'Menu Share',
             path: '/page/API/pages/share/share?a=b&from=' + opt.from,
             PCPath: '/page/API/pages/share/share?a=b&from=' + opt.from,
             PCMode: 'sidebar-semi',
             imageUrl: "https://xxx.jpg", // When you don't need to customize the preview image, you don't need to pass in the imageUrl parameter.
             success(res) {
                 console.log('success', res);
             },
             fail(errr) {
                 console. error(errr);
             },
         };
     }
})
```

## Configure the sharing function entry

After calling the onShareAppMessage function to realize the sharing function, you can share the gadget from the menu in the upper right corner of the gadget, or add a share button in the gadget to share.

### Entry 1: Share the gadget page from the menu

After configuring the sharing function on a certain page of the gadget, the user can see the sharing button in the menu list in the upper right corner when using the gadget and entering the page. Click **Share**, and choose to share with Feishu groups or individuals, and finally the shared information will be displayed in the chat in the form of a message card. Example operations are as follows:

1. In the menu in the upper right corner of the gadget, click **Share**.

![image.png](//sf3-cn.feishucdn.com/obj/open-platform-opendoc/5963f40f2a4fb2cd9079dcad3c1ec429_eaVMcuBUN4.jpg?height=668&lazyload=true&maxWidth=600&width=788)

2. After sharing to the designated Feishu session, you can view the message card information of the gadget.

When the user in the session clicks the card, it will jump to the page corresponding to the gadget.

![image.png](//sf3-cn.feishucdn.com/obj/open-platform-opendoc/1eb8488c06c7992ec06dbd99cdbb708b_YZPonwOT4g.png?height=1344&lazyload=true&maxWidth=300&width=768)

### Entry 2: Share the gadget page from within the app

You can add the [button](https://open.feishu.cn/document/uYjL24iN/uIjNuIjNuIjN) component to the specified page, and set the `open-type` corresponding to the component to `share` to share the gadget within the application. The example effect of the button component is shown in the figure below. If the user of the gadget clicks the share button and chooses to share with Feishu groups or individuals, the final shared message will be displayed in the Feishu session in the form of a message card.

![image.png](//sf3-cn.feishucdn.com/obj/open-platform-opendoc/8454c9f2427fb4d78e72fb4426ca3e03_cn6xVddUXX.jpg?height=872&lazyload=true&maxWidth=300&width=404)