OneBot-api icon

OneBot-api

Consume OneBot API

Overview

This node interacts with the OneBot API to manage member relationships in a messaging platform. Specifically, for the "成员关系" (Member) resource and the "批量操作" (Batch Operation) operation, it allows users to perform bulk actions such as leaving all group chats, deleting all friends, or both simultaneously. It supports using whitelists to exclude certain groups or friends from these batch operations and can optionally dismiss groups when leaving if the user is the owner.

Common scenarios where this node is beneficial include:

  • Cleaning up a user's social connections by removing unwanted friends or leaving inactive groups.
  • Automating mass exit from multiple group chats while preserving important groups via whitelist.
  • Managing friend lists efficiently by bulk deletion except for selected contacts.

Practical example:

  • A user wants to leave all group chats except a few important ones and also delete all friends except close contacts. They can select the "两者都执行" (both) mode, enable whitelist usage, and specify which groups and friends to keep.

Properties

Name Meaning
操作模式 (batch_mode) Choose the batch operation mode: "退出所有群聊" (leave all groups), "删除所有好友" (delete all friends), or "两者都执行" (both).
使用白名单 (use_whitelist) Whether to use a whitelist to exclude certain groups or friends from the batch operation.
群聊 Names or IDs (whitelist_groups) List of group names or IDs to exclude from batch group operations; selectable from existing groups or specified via expression.
好友 Names or IDs (whitelist_friends) List of friend names or IDs to exclude from batch friend deletion; selectable from existing friends or specified via expression.
是否解散群聊 (is_dismiss_batch) Whether to dismiss groups when leaving them (only applicable if the user is the group owner).

Output

The node outputs an array of JSON objects representing the results of the batch operations performed. Each item corresponds to the outcome of an individual operation (e.g., leaving a group or deleting a friend). The output includes success or error information per item.

If errors occur during execution, the output JSON will contain an error field with the error message and a success boolean set to false.

No binary data output is indicated for this operation.

Dependencies

  • Requires connection to a OneBot-compatible API endpoint.
  • Needs an API key credential configured in n8n to authenticate requests.
  • Uses internal helper methods to fetch friend and group lists dynamically for whitelist options.
  • The node depends on several internal modules handling different resource operations but specifically calls the member-related operation handler for this resource-operation combination.

Troubleshooting

  • Common issues:

    • Failure to retrieve friend or group lists may cause whitelist loading to fail, resulting in empty or incomplete exclusion lists.
    • Insufficient permissions (not being group owner or admin) may prevent dismissing groups or performing some batch operations.
    • Network or authentication errors with the OneBot API will cause operation failures.
  • Error messages:

    • "未知的资源类别" ("Unknown resource type"): Indicates an unsupported resource was selected.
    • Errors during API requests will be returned in the output's error field; check API credentials and network connectivity.
    • Whitelist retrieval errors are logged internally and may result in fallback empty lists.
  • Resolution tips:

    • Verify API credentials and ensure the bot has necessary permissions.
    • Confirm that the user running the batch operations is the owner or admin of groups intended for dismissal.
    • Use expressions carefully when specifying whitelist IDs to avoid invalid values.

Links and References

Discussion