Clarify your requirements
Before development, note that this document helps you set up the following scenario in Stream mode: when you @ mention an Enterprise bot in a group, the bot replies to your message by calling the Bot sends group chat messages API. You can run the sample demo provided in “Quick start” to get a hands-on experience of using an Enterprise bot.Prerequisites
- Complete the Configure an Enterprise bot process (select Stream mode as the message receiving mode).
- After the bot is created, add the bot to a group.
-
Complete the API permission request for the OpenAPI. You need to request the
Permission to send messages with an internal Enterprise bot. -
Prepare the development environment:
Development environment Description Java - JDK 1.8 or later installed - Maven 3 installed Python - Python 3
Quick start
-
Download the sample demo:
Sample Description Java stream-robot-group-message-quick-start-java.zip Python stream-robot-group-message-quick-start-python.zip -
Start the sample demo:
Type Description Java 1. Modify the parameters in the application.properties configuration file: - app.appKey: the Client ID of the app. For more information, see Client ID. - app.appSecret: the Client Secret of the app. For more information, see Client Secret. - robot.code: the code of the bot. For more information, see Bot ID. 2. Start the Application.java file. 3. @ mention the bot in the group and send a message. For example, @ mention the bot and send “Hello”. The bot replies with the message content. Python 1. Install dependencies: pip install alibabacloud-dingtalk dingtalk-stream. 2. Run the start command in the current file directory:python3 send_robot_group_message.py --client_id="your app client id" --client_secret="your app client secret" --robot_code="your robot code". Replace client_id, client_secret, and robot_code. For details on how to obtain these parameters, see the Java instructions. 3. @ mention the bot in the group and send a message. For example, @ mention the bot and send “Hello”.
Procedure
The following is a Java example. For the Python example, download the demo above.
-
Add the dependencies to the
pom.xmlfile of your project. -
Create the main method and start it.
- @ mention the bot in the group and send a message. The bot replies with the message content.
Related documents
- Bot receives messages
- Server-side Stream mode
- Bot sends group chat messages
- Message types supported by an Enterprise bot