Define the requirements
Before you start development, note that this document helps you send group chat messages by calling the Custom bot sends group messages API through the Webhook of a Custom bot. The demo uses the sign request method. To help you get started quickly, run the sample demo provided in the Quickstart section. This gives you an intuitive experience of using a Custom bot.Prerequisites
-
Complete the Create a Custom bot procedure.
Select sign request as the security setting for the Custom bot. For details, see Custom bot security settings.
- Complete the Get the Webhook URL of a Custom bot procedure.
-
Prepare the development environment:
Development environment Description Java - JDK 1.8 or later installed - Maven 3 installed Python - Python 3
Quickstart
-
Download the sample demo:
Sample Description Java custom-robot-group-message-quick-start-java.zip Python custom-robot-group-message-quick-start-python.zip -
Start the sample demo:
Type Description Java 1. Modify the main method parameters in customRobotGroupMessage.java: - CUSTOM_ROBOT_TOKEN: the access_token value of the bot app. For details, see Get the Webhook URL of a Custom bot. Note Enter only the access_token value from the Webhook URL, not the full Webhook URL. - SECRET: the sign request secret in the security settings. For details, see Custom bot security settings. - (Optional) USER_ID: the userId of the user. For details, see User userId. Internal Group: Enter the userId of the user to enable the @ feature. External Chat: When a bot calls the OpenAPI to send messages, the @ feature is not supported. 2. Start the main method. 3. The message sent by the Custom bot then appears in the group. Python 1. In the directory of the current file, run the following command: python3 send_custom_robot_group_message.py --access_token="your custom robot token" --secret="your custom robot secret" --userid="you need @ group user's userid". Replace the access_token of the bot Webhook, the sign request secret of the bot, and the user userid. For how to obtain these parameters, see the description in the Java section. 2. The message sent by the Custom bot then appears in the group.
Procedure
The following is a Java example. For the Python example, download the demo above.
-
Add the dependencies to the
pom.xmlfile of the project. -
Create the main method and start it.
The message sent by the Custom bot then appears in the group.
FAQ
Rate limit
To prevent sending messages too frequently from degrading the group chat experience, the rate limit for messages sent by a Custom bot is as follows:Each bot can send a maximum of 20 messages per minute to a group. If the limit is exceeded, the bot is rate-limited for 10 minutes.
If you have scenarios with a large volume of messages, such as system monitoring alerts, consolidate the messages and send them as a summary to the group using markdown messages.