gentle-lunch-37811
04/30/2024, 12:35 PMcold-jewelry-54343
04/30/2024, 4:09 PMfilter
method to get a specific range of records from your Tables e.g. `all records that begin with X" . You can go into the tables and set-up your query using the built-in Query maker, paste the code there, then paste and replace it in the following code:
js
try {
const clientNumbers = await Data1Table.findRecords({
filter: {"Phone":{"$regex":"^\\+55"}},
limit: 30,
offset: 0
})
workflow.phonearray = clientNumbers.map((product) => {
return {
name: product.name,
phone: product.Phone
}
})
} catch (error) {
console.log('Something went wrong: ', error)
}
Take a look in the following thread where I answered a similar question: https://discord.com/channels/1108396290624213082/1232337094685491290
I know it can be difficult to use code but you can build complex search queries with it. As an alternative you can look more into the QueryKnowledgeBase
card but in my personal experience code is superior.
https://cdn.discordapp.com/attachments/1234845603528441906/1234899418788925470/brave_buPYoCqrGp.png?ex=66326934&is=663117b4&hm=d9b195ff1523428e17aa51d8af92a93b480ffe2f6bfa58b73d56c205d4e7b442&gentle-lunch-37811
04/30/2024, 6:03 PMTitle: ${sermon.Title}, Preacher: ${sermon.Preacher}, DownloadLinks: ${sermon.DownloadLinks}
)
}
}
}
// Perform search based on user input
async function handleSearch() {
const keyword = workflow.SermonQuery // Get user input from workflow.SermonQuery
try {
const matchingSermons = await searchSermons(keyword)
workflow.userdownload = matchingSermons // Store the result in workflow.userdownload
displayMatchingSermons(matchingSermons)
} catch (error) {
console.error('Error searching for sermons:', error)
}
}
// Call handleSearch to start the search process
handleSearch() and it works well. however the problem i am having is that the result is displaying in the console and not as a text card. in the code i told it to display result in workflow.userdownload. its not doing this. i know its some minor thing left but i dont know what it is.gentle-lunch-37811
04/30/2024, 6:06 PMbumpy-butcher-41910
04/30/2024, 7:32 PMbumpy-butcher-41910
04/30/2024, 7:32 PMbumpy-butcher-41910
04/30/2024, 7:33 PMcold-jewelry-54343
04/30/2024, 7:47 PMhandleSearch() and it works well. however the problem i am having is that the result is **displaying in the console **and not as a text card. in the code i told it to display result in workflow.userdownload. its not doing this. i know its some minor thing left but i dont know what it is.
js
async function searchSermons(keyword) {
try {
// Assuming Botpress provides a method to query data from the TcnSermonTable
const tableData = await TcnSermonTable.findRecords({
filter: {
Title: { $regex: keyword, $options: 'i' }
}
});
const results = tableData.map((row) => ({
Title: row.Title,
Preacher: row.Preacher,
DownloadLinks: row.DownloadLinks
}));
return results;
} catch (error) {
console.error('Error retrieving data from TcnSermonTable:', error);
return []; // Return an empty array if there's an error
}
}
// Function to display matching sermons
function displayMatchingSermons(matchingSermons) {
if (matchingSermons.length === 0) {
workflow.matchingSermonsMessage = 'No sermons found matching the keyword.';
} else {
let message = "";
for (const sermon of matchingSermons) {
message += `Title: ${sermon.Title}, Preacher: ${sermon.Preacher}, Download Links: ${sermon.DownloadLinks}\n`;
}
workflow.matchingSermonsMessage = message;
}
}
// Perform search based on user input
async function handleSearch() {
const keyword = workflow.SermonQuery; // Get user input from workflow variable
try {
const matchingSermons = await searchSermons(keyword);
workflow.userdownload = matchingSermons; // Store the result in workflow variable
displayMatchingSermons(matchingSermons);
} catch (error) {
console.error('Error searching for sermons:', error);
workflow.matchingSermonsMessage = 'An error occurred while searching for sermons.';
}
}
cold-jewelry-54343
04/30/2024, 7:47 PMworkflow
variables used inside the code like
workflow.userdownload
(to do so, go the left variable tab + create variable and call it workflow.userdownload).
The reason btw why your code does not work is that variables in Botpress need to be declared using the workflow
prefix ( theres also user, session but these are usecase specific)gentle-lunch-37811
04/30/2024, 8:12 PMgentle-lunch-37811
05/01/2024, 11:06 AMgentle-lunch-37811
05/01/2024, 10:04 PMcareful-shoe-96396
05/10/2024, 5:48 AMgentle-lunch-37811
05/10/2024, 6:56 AM