DEV Community

Cover image for Internal Case Sharing: An AI Data Analysis Bot Built by Momen Marketing Team
Alex for Momen

Posted on • Updated on

Internal Case Sharing: An AI Data Analysis Bot Built by Momen Marketing Team

Introduction

Data tracking is vital for marketing, but manual analysis can be time-consuming, especially for non-technical teams. In this article, we share how Momen’s marketing team streamlined data analysis using Momen AI.


Overview

Momen's marketing team build an AI data analysis bot. This agent is integrated in our team communication app. 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.

overview of an ai agent

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:

  1. Obtaining raw data and writing it into the database
  2. Creating an Actionflow in Momen to process the data
  3. Building an AI that invokes this Actionflow as a tool
  4. Integrate it into Lark.

steps of building an ai agent

💡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.

Step-by-Step Guide

1. Creating the Data Model

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.

data models in a no code tool


2. Retrieve Data from External App

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.

testing api

Then we request API in Momen's API configuration.

configure API in a nocode tool

Then add a node in the actionflow to get this data. After that, we can proceed with inputting data.

actionflow in a nocode tool


3. Input Data into Momen's Database

Momen provides two ways to input data: using Momen actionflow's triggers or leveraging external tools with callbacks.

3.1 Scheduled Actionflow Calls in Momen

In Actionflow triggers, you can use the built-in scheduling feature. Your tasks will be executed automatically at specific intervals.

input data in a no code tool

You can either choose from predefined intervals or write your own cron job expression for custom scheduling.

cron job

3.2 External Callbacks with Actionflow

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.

callbacks

Configure inputs/outputs as needed for your specific application.

Image description

Image description

3.3 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.

Input data in a no-code tool


4. Building an Actionflow to Process Data

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.

javascript in actionflow of a no code tool

The Actionflow logic is simple: fetch the existing data from the database and calculate the values for each step in the conversion path.


5. Creating AI for Data Analysis

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.

build an ai agent in a no-code tool

5.1 Setting Input

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.

setting ai input in a no-code tool

5.2 Writing the Prompt

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).

Momen AI

5.3 Providing Tools

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.

momen ai

ai configuration

5.4 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.

json output in ai

While in Momen, you can specify built-in JSON formats for easy integration. This makes the analysis result from your AI more accurate.

structured output of momen ai

5.5 Debugging the Agent

Momen allows you to debug the AI, view the conversation details, tool invocations, and make necessary adjustments to refine the agent.
.


6. Lark Bot Integration

6.1 Register and Obtain Permissions in Your Communication App

Make sure you've registered and enabled communication on the developer platform of your communication app. In this case we used Lark.

Image description

6.2 Linking the Bot to Actionflow

Configure an API callback to match the Lark. You can find the API document in your app's developer platform.

Image description

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>"
Enter fullscreen mode Exit fullscreen mode

Then return the challenge. Only when this condition is met can the callback pair with the bot.

Image description

After matching, you can modify the bot's responses.

6.3 Modifying Bot's Responses Using Actionflow

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"
}
Enter fullscreen mode Exit fullscreen mode

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.

Image description

6.4 Testing the Result

The last step is to test it in the conversation to see if the bot returns the responses you expected.

Image description


Conclusion

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.

Top comments (3)

Collapse
 
zachzqy profile image
ZachZQY

woooo

Collapse
 
chomping profile image
taro

nice

Collapse
 
alexcc522 profile image
Alex

Thanks!