# Send message cards with custom bot

Feishu message cards allow you to send and receive structured (JSON structured data) messages through bots or apps. This allows you to push activity notifications, business approvals, monitoring alerts, schedules, and more using message cards. This article will describe how to send card notifications through a group bot.warning
This document refers to legacy message cards and is no longer maintained. To view the corresponding updated documentation, refer to [Sending Feishu Cards with Custom Bots](https://open.feishu.cn/document/uAjLw4CM/ukzMukzMukzM/feishu-cards/quick-start/send-message-cards-with-custom-bot).

## Example effect

By following the steps in this article, you can achieve the effect shown in the following image, which is pushing an example message card through a custom bot in a group.

![](//sf3-cn.feishucdn.com/obj/open-platform-opendoc/1198f5d73c7fa208278ce50b4432e86c_Y5uxXtrlkA.png?height=1538&lazyload=true&maxWidth=600&width=2740)

## Procedure

### Step 1: Preparation

This article will use Python code to send the message card, so the following preparations need to be completed.

1. Install Python runtime environment in the local development environment.

For official installation methods, see [Python](https://www.python.org/).

2. In the local terminal, use the `pip` command to install the `requests` package.

Different Python versions have different commands:

- If you have installed Python 2, the command is as follows.

```
        pip install requests
        ```
    - If you have installed Python 3, the command is as follows.

```
        pip3 install requests
        ```

### Step 2: Create a message card

1. Open the [Message Card Builder](https://open.feishu.cn/tool/cardbuilder) page.

2. On the Message Card Builder page, click on **Best Practices** on the left side, select a message card template, and then click **Use**.

In this article, select the **Multi-language message card** template.

![](//sf3-cn.feishucdn.com/obj/open-platform-opendoc/43f87d7cd571f394c774ac40405f293f_l1iilS9YJs.png?height=1424&lazyload=true&maxWidth=600&width=2882)

3. (Optional) Edit the card content.

You can click on the card content in the **Preview in English** area to make modifications. For information about constructing card content, refer to the [Message Card Design Specification](https://open.feishu.cn/document/ukTMukTMukTM/ugDOwYjL4gDM24CO4AjN) and [Card Structure Introduction](https://open.feishu.cn/document/ukTMukTMukTM/uEjNwUjLxYDM14SM2ATN).
In this example, no modifications are made to the **Multi-language message card** card; the template is used directly for demonstration.

![](//sf3-cn.feishucdn.com/obj/open-platform-opendoc/84cefaa6e445acfe5c39fd55e8352f4f_qKJo6FG9fJ.png?height=1432&lazyload=true&maxWidth=600&width=2882)

4. Click **Save and Publish** in the upper right corner of the page, and then click **Publish** in the pop-up dialog box.

![](//sf3-cn.feishucdn.com/obj/open-platform-opendoc/68676b8dcae618e020b1b81d909d1968_9Lf6LZJRgB.png?height=1420&lazyload=true&maxWidth=600&width=2882)

### Step 3: Create a custom bot for the group

1. Log in to the Feishu client (PC).

2. Select a target group and click **Bots** in the group settings.

![](//sf3-cn.feishucdn.com/obj/open-platform-opendoc/8169085c4bf399f0a467c4a5995a4706_Q6nI82ZI5z.png?height=1532&lazyload=true&maxWidth=600&width=1798)

3. Click **Add Bot** and select **Custom Bot**.

![](//sf3-cn.feishucdn.com/obj/open-platform-opendoc/1beb0c9b05e8768e324e8723f7f35646_5mHzBwqpX6.png?height=1516&lazyload=true&maxWidth=600&width=2714)

4. Confirm the bot's avatar, name, and description, then click **Add**.

![](//sf3-cn.feishucdn.com/obj/open-platform-opendoc/f24fcaa4e3b87bd4b9493b53c3b6d72b_CQrxY2VfiY.png?height=1148&lazyload=true&maxWidth=600&width=1664)

5. After adding, properly save the webhook URL of the bot and click **Finish**.    
Further requests need to be sent to the webhook URL of the bot to send message cards. Therefore, you need to save this webhook, ensure data security, and prevent others from maliciously calling the bot. 

![](//sf3-cn.feishucdn.com/obj/open-platform-opendoc/5eef67a22d4c6b79418b3fa6fa295093_Afwh6YstGi.png?height=1140&lazyload=true&maxWidth=600&width=1668)

### Step 4: Send message card

1. Create a Python file named `main.py` locally.

2. Open the `main.py` file with your local code editor, and add the following code to the file. Manually configure the relevant parameters.
    ```python
    import requests
    import json
    ## Replace with the webhook address of your custom bot.
    url = "https://open.feishu.cn/open-apis/bot/v2/hook/xxxx"
    ## Paste the message card content here.
    card_json = r'''
    {
      "config": {
        "wide_screen_mode": true
      },
      "elements": [
        {
          "alt": {
            "content": "",
            "tag": "plain_text"
          },
          "img_key": "img_v2_bfd72a81-1533-4699-995d-12a675708d0g",
          "tag": "img"
        },
        {
          "tag": "div",
          "text": {
            "content": "Have you ever had a deep connection and started to contemplate life because of a book?\nWhat are some treasured books that you would highly recommend to others?\n\nJoin the **4·23 Feishu Reading Festival** and share your **beloved book list** and **book notes** to **win book rewards worth 1,000 yuan**!\n\n📬 Fill out the questionnaire and show off your treasured books\n😍 Want to know what other people have recommended? [Join the group](https://open.feishu.cn/) right away\n📝 Use the [book note template](https://open.feishu.cn/) (open on desktop) to record your thoughts and experiences\n🙌 Special guest invitation with surprises starting from April 12th to read together",
            "tag": "lark_md"
          }
        },
        {
          "actions": [
            {
              "tag": "button",
              "text": {
                "content": "Recommend a Book Now",
                "tag": "plain_text"
              },
              "type": "primary",
              "url": "https://open.feishu.cn/"
            },
            {
              "tag": "button",
              "text": {
              "content": "View Activity Guide",
                "tag": "plain_text"
              },
              "type": "default",
              "url": "https://open.feishu.cn/"
            }
          ],
          "tag": "action"
        }
      ],
      "header": {
        "template": "turquoise",
        "title": {
          "content": "📚Show Beloved Books and Win Reading Rewards",
          "tag": "plain_text"
        }
      }
    }
    '''
    body = json.dumps({"msg_type": "interactive", "card": card_json})
    headers = {"Content-Type": "application/json"}
    res = requests.post(url=url, data=body, headers=headers)
    print(res.request.body)
    print(res.text)
    ```

Parameter value configuration:

- Custom bot webhook address: Enter the webhook address of the bot you have saved.

- Message card content refers to the JSON data of the card, which can be obtained as follows:

1. Open the [Message Card Builder](https://open.feishu.cn/tool/cardbuilder) page.

2. Open the **Multi-language message card** card that has been created and saved.

3. In the **Edit card** section, click the code icon to obtain the JSON data.

![](//sf3-cn.feishucdn.com/obj/open-platform-opendoc/b65022c27595a57ef475a724f15121a5_379uuHEtL4.png?height=1444&lazyload=true&maxWidth=600&width=2882)    

3. Save the file and run the `main.py` file with the following command at the file's location.

- For Python 2 environment, execute the following command:

```
        python main.py
        ```

- For Python 3 environment, execute the following command:

```
        python3 main.py
        ```

4. View the message card information in the Feishu client group.

![](//sf3-cn.feishucdn.com/obj/open-platform-opendoc/8de3eb2222f12911577ca67aeb2267b0_JRpt9bmOHK.png?height=1562&lazyload=true&maxWidth=600&width=2880)