nonebot.adapters.feishu

website·Indexed 31 days ago

https://adapter-feishu.netlify.app

Documentation for the Feishu adapter for NoneBot, featuring WebSocket long connection modules, bot configuration via BotConfig, and event handling. Includes API references for versions 2.7.1, 2.7.2, and Next.

Tokens
13.9K
Snippets
92
Records
144
Agent score
68%

What's inside nonebot-adapter-feishu

  1. Use the Feishu Adapter to manage bot connectivity

    The Adapter class in nonebot.adapters.feishu is the core component that connects NoneBot to the Feishu platform. It handles the lifecycle of the bot connection, API request routing, and the transformation of raw JSON data into structured Event objects.
  2. Configure Feishu event subscription endpoint

    In the Feishu Open Platform under Development Configuration > Events and Callbacks, set the event subscription reporting endpoint using the following format. Replace $HOST and $PORT with your server details and $app_id with the specific bot's App ID.
    http://$HOST:$PORT/feishu/$app_id
  3. Configure Feishu event subscription endpoint

    In the Feishu Open Platform under Development Configuration > Events and Callbacks, set the event subscription reporting endpoint using the following format:

    http://$HOST:$PORT/feishu/$app_id

    Replace $HOST and $PORT with the values defined in your .env file, and $app_id with the specific App ID provided by the Feishu Open Platform. When selecting events to subscribe to, avoid those marked as '(Historical Version)' and use the newer versions instead.

  4. Configure Feishu event subscription endpoint

    In the Feishu Open Platform under Development Configuration > Events and Callbacks, set the event subscription reporting URL using the following format. Replace $HOST and $PORT with your server's address and port, and $app_id with the specific bot's App ID.
    http://$HOST:$PORT/feishu/$app_id
  5. Create interactive Feishu message cards

    Feishu supports rich interactive messages. You can create them using either a custom configuration or a predefined template via MessageSegment.
    from nonebot.adapters.feishu import MessageSegment
    
    # 1. Using a custom interactive card
    # Requires InteractiveHeader and InteractiveConfig objects
    interactive_seg = MessageSegment.interactive(
        header=header_obj, 
        config=config_obj, 
        elements=[...], 
        i18n_elements=[...]
    )
    
    # 2. Using a template
    template_seg = MessageSegment.interactive_template(
        template_id="template_id_here", 
        template_variable={"key": "value"}
    )
  6. Install and configure drivers for Feishu adapter

    The Feishu adapter requires both a forward driver (e.g., httpx) and an ASGI driver (e.g., fastapi) to be installed and enabled in the NoneBot environment.
    pip install nonebot[httpx] nonebot[fastapi]

    In .env file:

    DRIVER=~fastapi+~httpx

  7. Install and configure drivers for Feishu adapter

    The Feishu adapter requires both a forward driver (for sending requests) and an ASGI driver (for receiving events). It is recommended to use httpx and fastapi.
    pip install nonebot[httpx] nonebot[fastapi]

    In .env file:

    DRIVER=~fastapi+~httpx