In CometChat, custom agents are unique users capable of autonomously sending and receiving messages.Users can interact with agents through private one-on-one conversations or within group chats. When an agent receives a message, whether from an individual chat or a group, CometChat relays that message to a Callback URL that you configure. Upon receiving the message, you can process it according to your business logic and send a response using CometChat’s API.
It is recommended to set up a Basic Authentication that is usually used for server-to-server calls. This requires you to configure a username and password. Whenever your callback endpoint is triggered, the HTTP Header will contain:
CometChat requires each bot to be linked to a user account. This approach offers a significant benefit: It allows you to log in as the bot at any time and send personalized responses.Therefore, before setting up a bot, you must first create a new user. You can create a user from CometChat dashboard or make use of CometChat’s Create user REST API to do so.
Navigate to AI Agents > Custom Agents in the left-hand menu.
Add a new agent.
Configure the agent by saving the following details:
UID: The identifier (UID) of the user that was created in the previous step.
URL: The callback URL of your agent.
Group Setting: Select the criteria for relaying a group message to your agent.
Security: It is recommended to enable authentication for your callback URL.
Enable the agent.
Save the configuration.
The actual development and behavior of the agent are completely in your hands. All you need to do is provide a Callback URL, and CometChat will then automatically relay all messages that meet the specified criteria to that URL.
After your bot’s callback endpoint has received and processed a message, and you’re ready to send a response back, make use of CometChat’s Send Bot Message REST API to do so.