Define your requirements
Before you start development, review the following overview. This document helps you, in Stream mode, send a message to the bot during a direct chat. The bot then replies to your message by calling the Send one-on-one chat messages between users and bots in batches API. Try running the sample demo provided in “Quick start” to get a hands-on experience with the enterprise bot.Prerequisites
- Complete the Configure the enterprise bot process (select Stream mode for the message receiving mode).
-
Complete the API permission application for the OpenAPI endpoint. Request the
Permission to send messages from an internal botscope. -
Prepare the development environment:
Development environment Description Java - JDK 1.8 or later is installed - Maven 3 is installed Python - Python 3
Quick start
-
Download the sample demo:
Sample Description Java stream-robot-private-message-quick-start-java.zip Python stream-robot-private-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 details, see Client ID. - app.appSecret: the Client Secret of the app. For details, see Client Secret. - robot.code: the code of the bot. For details, see Bot ID. 2. Start the Application.java file. 3. Send a message to the bot in a direct chat, for example, “Hello”. You can then see the message sent by the bot. Python 1. Install dependencies: pip install alibabacloud-dingtalk dingtalk-stream. 2. In the current file directory, run the startup command:python3 send_robot_private_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 how to obtain these parameters, see the instructions in the Java section. 3. Send a message to the bot in a direct chat, for example, “Hello”.
Procedure
The following is a Java example. For the Python example, download the demo from the section above.
-
Add the dependencies to the project’s
pom.xmlfile. -
Create the main method and start it.
- Send a message to the bot in a direct chat. You can then see the message sent by the bot.
Related documents
- Bot receives messages
- Server-side Stream mode
- Message types supported by enterprise bots
- Send one-on-one chat messages between users and bots in batches