This document provides example prompts and application scenarios for using O-mind. It encompasses both basic and advanced functionalities, including object manipulation, message generation, card and list responses, API integrations, and external data retrieval. You can use these examples to streamline chatbot development and enhance automation capabilities within your workflows.
Basic Usage
Basic usage covers fundamental O-mind functions, including object manipulation, text and image responses, and structured message formats like cards and lists. These examples help in implementing core chatbot interactions efficiently.
Object manipulation with a prompt and parameter return
This section demonstrates how you can extract, clean, and process data from an object using a prompt. The example below showcases retrieving a phone number, formatting it, extracting relevant details, and returning structured parameters to the bot for further use.
- Example lambda: GetUserInfo
- Example prompt: Hello! Retrieve the clientPhone value from the CLIENT_INFO object. If this value does not exist, use an empty string (''). Clean the phone number by removing the + sign and assign the result to the phone variable. Then, calculate the length of the phone number and assign this value to the phoneLength variable. Extract the country code, which is part of the phone number at the beginning, with a length of phoneLength - 10, and assign this to the countryPhoneCode variable. Finally, return the following parameters to the bot:
- countryPhoneCode (country code)
- countryPhoneCodeWithPlus (country code prefixed with +)
- phone (cleaned phone number)
- phoneWithPlus (phone number prefixed with +)
- phoneWithoutCountryCode (last 10 digits of the phone number).
- Example CodeStation: generateGetUserInfoWithAi
Returning messages with the Text Module
This section explains how to generate and return a text module to the bot. The example demonstrates structuring and delivering predefined text responses, enabling clear and consistent communication within chatbot interactions.
- Example prompt: Hello! I will return a text module to the bot. The text is as follows: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
- Example CodeStation: generateTextMessageWithAi
Creating visual responses with the Image Module
This section covers generating and returning an image module to the bot. The example demonstrates providing an image URL as a response, allowing for richer and more engaging chatbot interactions.
- Example prompt: Hello! We will return an image module to the bot. The image URL will be as follows: https://miro.medium.com/v2/resize:fit:1400/format:webp/1*NxqtFLQg8jky16TF84Gifw.jpeg
- Example CodeStation: generateImageWithAi
Card Message
This section provides examples of creating and returning a Card Message to the bot. The example demonstrates configuring a card with a title, subtitle, image, and interactive buttons, enhancing chatbot responses with structured and visually engaging content.
- Example prompt: Hello, we will return a Card Message to the bot. I want to configure it with the following parameters:
- inputParam value: age
- errorMessage value: invalid input
- fallback value: 1
- fallbackCount value: 2
In the payload section:
- title value: Istanbul
- subtitle value: Kadıköy
- image value: https://miro.medium.com/v2/resize:fit:1400/format:webp/1*_8Acf_kCVHbMnli8LFKjXA.jpeg
In the button section:
- text value: Select
- value value: 12
- action value: testAction
Using these parameters, you can create a ChatBotCard.
- Example CodeStation: generateCardWithAi
List Message
This section covers how to create a List Message for the bot. The example demonstrates configuring a structured list with headers, descriptions, and selectable options, enabling organized and interactive chatbot responses.
- Example prompt: Hello, we will return a List Message to the bot. I want to configure it with the following parameters:
- inputParam value: testParam
- errorMessage value: invalid input
- fallback value: 1
- fallbackCount value: 2
- listHeader value: Test header
- messageBoxBody value: messageBoxBodytest
- messageBoxOptionsButtonText value: hello2
In the payload section:
- listSectionTitle value: Test
- listCardRow values should be as follows:
- listRowId value: 1
- listRowTitle value: title
- listRowDescription value: test description
- value value: 5
Using these parameters, create a ListMessage and return it to the bot.
- Example CodeStation: generateListMessageWithAi
Advanced Usage
Advanced usage covers more complex scenarios such as API requests, data retrieval, and integrations with external platforms like Google Sheets and Airtable. These use cases enable advanced automation and dynamic content generation.
List orders with a card using HTTP requests
Hello, we want to create a Card Module for the bot. The configuration should include the following:
- The params value will expect productId, which must be a string and cannot be empty or null.
- An Axios request will be made:
- URL: https://dummyjson.com/carts/${productId}
- Method: GET
- After the request, the response must have:
- Status: 200
- Content: A populated object
- The response.data object format should include:
- id (number)
- products (array of objects)
- total (number)
- discountedTotal (number)
- userId (number)
- Card Module parameters:
- inputParam: selectedProduct
- errorMessage: invalid input
- fallback: 1
- fallbackCount: 2
- Card Payloads section:
- The products array will be dynamically mapped:
- title: title
- subtitle: price
- image: thumbnail
- The products array will be dynamically mapped:
- Button section:
- text: Select
- value: 12
- action: id
Using these details, create a ChatBotCard.
- Example CodeStation: generateListMessageWithAi
List Reply
A. Hello, we expect the following values from params:
- customerId (string, cannot be empty)
- orders (array object, cannot be empty)
- fallback (string, cannot be empty)
- value (string, cannot be empty)
Additionally, we expect the following optional parameters:
- valueForKaydiGor
- reason
You can take a look at the flow:
1. After validation, make an Axios request to the partner service:
- URL: https://xyz.com/crm/chatbot/CustomerService/GetCustomerCaseListForCustomerNo/${customerNo}
- Method: GET
- Header: ApiKey: 123456
2. If the response status is 200 and response.data is not null, assign this value to casesResponse.
- If the status is 404, return the parameter errorReason: Customer case not found to the bot.
- If the status is 5xx, throw an error and trigger the fallback defined in the catch block.
3. Define the cases variable (default is null). Use a predefined string array caseCodes with these values:
'SS00057', 'SS00056', 'SS00060', 'SS00099', 'SS00063', 'SS00071', 'SS00062', 'SS00062', 'SS00069'.
4. If the casesResponse length is greater than 0, filter the casesResponse based on whether the subtopicCode in casesResponse includes any value in the caseCodes array. Assign the matching results to cases.
5. Return a CardMessage to the bot with these values:
- Input Parameter: shippingNo
- Fallback Value: Comes from params
- Payloads:
- Map the cases array to a set:
- Title: *Shipping Company:* ${item.shippingCompany != null ? item.shippingCompany : '-' }\n*Order Date and Time:* ${item.shippingDateFormatted} *A record has been created for this order.*
- Text: Empty string
- Image: item.products[0].productImage
- Buttons:
- Text: SELECT
- Action: item.shippingListNo
- Value: params.valueForKaydiGor
- Map the cases array to a set:
B. Hello, we expect the productId value from params. This value must be a string and cannot be empty.
- Make a request to: https://dummyjson.com/carts/${productId}
- If the response status is OK, assign the response.data.products array to a variable named products.
- Return a ListMessage Module with these parameters:
- inputParam, errorMessage, fallback, fallbackCount, listHeader, messageBoxBody, messageBoxOptionsButtonText (values from params).
- Payloads Section:
- listSectionTitle: test title
- Map the products array to create:
- ID: i+1
- Title: x.total TL (as a string)
- Description: x.title
- Value: Set using the value from params.
Loop to create text messages
Hello, we expect the productId value from params. This value must be a string and cannot be empty.
- Make a request to: https://dummyjson.com/carts/${productId}
- If the response status is OK, assign the response.data.products array to a variable named products.
- Return a Text Message Module, but first map the products array to extract the x.title values and send them as individual text messages.
Card Selection as List Selection
I want to list users as a list selection using https://dummyjson.com/users as the API. Create a list selection for web chat, but display it as a Card Selection with buttons underneath. The list will be built as clickable buttons. Avoid using "require".
List Selection Example
Hello, make a request to https://dummyjson.com/users and map the response data into a List Selection.
- The listSectionTitle should be: User List.
- The listRowTitle should be: name.
Avoid using 'require'.
Card Selection Example
Hello, make a request to https://dummyjson.com/users and construct the response data as Card Selection.
- The button text should be: Select.
- The card details should include the user’s name and other details.
Avoid using 'require'.
Google Spreadsheet Integration Example
In this section, you can learn how to fetch data from a Google Spreadsheet using JavaScript. This example demonstrates authentication, retrieving sheet data, handling errors, and logging, ensuring seamless integration with chatbot workflows.
- Prompt: Hello, write a JavaScript function to fetch data from a Google Spreadsheet.
- Requirements:
1. Use SECRET_MANAGER.CUSTOM to retrieve client_email and private_key.
2. Use BOT_PARAMETERS to get sheetId and sheetName.
3. Create a helper function named getSheet to:
- Authenticate the client.
- Find the sheet specified by sheetName.
- Fetch rows using getRows.
- Match headers and data to create an array of data objects.
4. If data exists, return isFound: true with the data. Otherwise, return isFound: false.
5. Add a logging function named logHelper for monitoring.
6. Handle errors gracefully and return a fallback response in case of an error.
Airtable Integration Example
In this section, you can learn about retrieving records from Airtable using JavaScript. The example below demonstrates authentication, searching by parameters, returning relevant fields, and handling errors efficiently.
- Prompt: Hello, create a JavaScript function that works with Airtable.
- Requirements:
1. Use SECRET_MANAGER.CUSTOM to retrieve baseID, tableID, and apiKey.
2. Search for a record in Airtable using keys from the params object (airtable_params_*) and today’s date (useDate).
3. If a matching record is found, return the fields couponNo and wpmessage.
4. If no record is found or an error occurs, return an appropriate error message.
5. Use logger.info for logging.
6. Implement robust error handling.
Find the nearest store by location
This section demonstrates how to find the nearest store based on the user's location.
- Prompt: Hello, fetch the nearest store based on the user’s location.
- Requirements:
1. Retrieve the location parameter as a string array from BOT_PARAMETER.
2. Validate the input.
3. Make a request to the following URL: https://turkey-geolocation-rest-api.vercel.app/cities?fields=city,lat,lon
4. The response structure will be: data.data: { city: string; lat: number; lon: number; }[]
5. Process the location value: Split the string using commas to extract lat (first value) and lon (second value).
6. Use the coordinates to determine:
- The nearest city.
- The distance to other cities (in kilometers).
7. Return the parameters nearCity (the nearest city) and farAwayKm (distance to other cities).