Momen's marketing team build an AI data analysis bot. This agent is integrated in our team communication app Lark. Simply mention the bot in the conversation and send instructions like "Give me the conversion rate in the last 7 days". The bot will present the conversion data analysis result.
Using Momen's API, Actionflow, and AI features, we’ve created a AI data analysis bot integrated with Lark.
The building process can be broken down into four steps:
🔍Feature explanation
API connects Momen to external tools. In this case, it fetches raw data from external databases and uses it within agents.
Actionflow in Momen is like creating your own custom logic and workflows for apps. It save your time by automating pre-configured actions and recurring workflows on the back-end when triggered.
Momen AI is Momen's flexible GenAI app development framework which enables you to build AI agents that automatically plan and execute tasks.
Our focus is conversion rates, so the first step is to outline the user conversion path from registration to create diffs. In our case, the path will be: total visits -> total registrations -> onboarding loaded -> form filled -> project created -> diff created -> 100 diff created. With this path in mind, we then define the data model. While this is just a reference, each app will require adjustments based on specific needs.
Before getting started with Momen, we need to retrieve the data we stored in the external database. Normally we can do this via API. Test and configure your API in Postman.
Then we request API in Momen's API configuration.
Then add a node in the actionflow to get this data. After that, we can proceed with inputting data.
Momen provides two ways to input data: using Momen actionflow's triggers or leveraging external tools with callbacks.
In Actionflow triggers, you can use the built-in scheduling feature. Your tasks will be executed automatically at specific intervals.
You can either choose from predefined intervals or write your own cron job expression for custom scheduling.
Another way to trigger data input is through an external callback. A callback allows a function to specify what to do after a certain task is completed.
Configure inputs/outputs as needed for your specific application.
Input Data via Custom Code
Whether you use a schedule or callback, data is written to the Momen database through the GraphQL API. Configure this step in the actionflow.
Raw data alone won’t provide meaningful insights. By using an actionflow, you can preprocess the data using mathematical/statistical methods, providing the AI with cleaner data for more accurate analysis.
Below is an example of key data calculated using a JavaScript code block in Actionflow, based on the conversion path and database. We complete this step after the data is retrieved from the database. You can also directly retrieve the processed data.
The Actionflow logic is simple: fetch the existing data from the database and calculate the values for each step in the conversion path.
Now we build an AI agent to analyze the processed data. There are four key parts to configuring AI: setting the input, writing the prompt, providing tools, and defining the output structure.
For this project, we need two inputs: the user's question and the current time. The question is the message you sent to the bot. The current time is the time range of the data you'd like AI to process.
In Momen, the prompt consists of three sections: Task Role, Task Details, and Task Constraints.
Task Role: Defines the AI's perspective (e.g., expert data analyst).
Task Details: Outlines the steps for the AI to follow, often broken down to ensure clear understanding.
Task Constraints: Specifies any formatting or style restrictions (e.g., JSON output).
The Actionflow built earlier serves as a tool the AI can invoke. You describe the tool’s purpose, input/output, and how it works. Based on the prompt, the AI will decide when to use the tool.
Defining Output Structure
In some complex scenarios, AI agent may need to interact with code. In this case, a proper JSON format output would help AI to process data more accurately. The example below is a common issue that AI has. When you want an answer in JSON format, it still gives you the response with strings.
While in Momen, you can specify built-in JSON formats for easy integration. This makes the analysis result from your AI more accurate.
Debugging the Agent
Momen allows you to debug the AI, view the conversation details, tool invocations, and make necessary adjustments to refine the agent. See the details here:
Make sure you've registered and enabled communication on the developer platform of your communication app. In this case we used Lark.
Configure an API callback to match the Lark. You can find the API document in your app's developer platform.
You need to configure a special API in Actionflow to match the bot by providing an input like this:
"challenge": "<test code>", "type": "url_verification", "token": "<your verification token>"
Then return the challenge. Only when this condition is met can the callback pair with the bot.
After matching, you can modify the bot's responses.
After successful pairing, all bot actions will be triggered through the callback, enabling real-time response.
You can obtain the request body with this code:
const body = context.getArg('fz_callback_body'); //body { "event": { "sender": { "sender_id": { "open_id": "ou_b8a516813350dfb09edacf406d66a6f7", "user_id": "bcc1465g", "union_id": "on_fee475043dcd1629c4cffddad71ea26a" }, "tenant_key": "2eaceddfba4f165b", "sender_type": "user" }, "message": { "chat_id": "oc_934c092aa4b6dca5370634dfe729b3e3", "content": "{\"text\":\"@_user_1 24年8月26日\"}", "mentions": [ { "id": { "open_id": "ou_e10e9d23300a60022ab94534483a8477", "user_id": "", "union_id": "on_e9044279f219beb91359f42cc6ad9ed6" }, "key": "@_user_1", "name": "bot", "tenant_key": "2eaceddfba4f165b" } ], "chat_type": "group", "message_id": "om_212f1792abed531d78e9c9e022e37b36", "create_time": "1724920813230", "update_time": "1724920813230", "message_type": "text" } }, "header": { "token": "X6NLX9Q8ChtcSppghkkt9fi0l4dgPeXT", "app_id": "cli_a409cb4bc9781013", "event_id": "c41159c72044df26d140eb6b9b5f2967", "event_type": "im.message.receive_v1", "tenant_key": "2eaceddfba4f165b", "create_time": "1724920813495" }, "schema": "2.0" }
The structure of the body looks like this, and you can use the logic to capture the information from bot. Then you can return the AI's response to the conversation.
The last step is to test it in the conversation to see if the bot returns the responses you expected.
No more data extraction and writing SQL queries. Momen AI has helped our marketing team improve workflow efficiency. We now can get faster insights while reducing technical dependency.
Ready to automate your own workflows? Start building your AI agent and transforming your team's processes: https://momen.app