https://discord.gg/botpress logo
Writing to an internal table
# 🤝help
d
I tried using the AI on botpress to help for hours. Here is the error 22:23:36 error dm dm CRITICAL WARNING: Failed to save lead to internal Botpress table. CRITICAL WARNING: Failed to save lead to internal Botpress table. Cannot read properties of undefined (reading 'createTableRows') {"scope":"dm"} #here is my action
HEre is my code, had to chop it up
// 0: LOCAL BACKUP TO BOTPRESS TABLE --- try { // This is our fail-safe. We write the core lead data to the internal table first. await bp.tables.createTableRows('LeadsTable', { rows: [ { name: user.lead_name, email: user.lead_email, role: user.user_persona, pain: conversation.primary_pain, timeline: conversation.timeline, budget_confirmed: conversation.budget_confirmed ?? false } ], waitComputed: true // optional but recommended }) bp.logger.info('Successfully saved lead to internal Botpress LeadsTable.') } catch (error) { // If the local backup fails, we log a critical warning but DO NOT stop. // The primary mission is to send the lead to the main backend. bp.logger.error('CRITICAL WARNING: Failed to save lead to internal Botpress table.', error.message) }
const payload = { // Creative Data (From LLM) name: input.name?.trim(), email: input.email?.trim().toLowerCase(), role: input.role, pain: input.pain, timeline: input.timeline?.trim() ?? '', budget: conversation.budget_confirmed ?? false, summary: event.state.conversation.SummaryAgent?.summary ?? '', transcript: event.state.conversation.SummaryAgent?.transcript ?? '', // System Data (From Botpress Env) user_id: event.userId, conversation_id: event.conversationId, source: 'botpress_realee_website', timestamp: new Date().toISOString() } // 2. Define URL const url = env.BACKEND_URL if (!url) { bp.logger.error('CRITICAL CONFIGURATION ERROR: env.BACKEND_URL is not set in Bot Settings.') throw new Error('System configuration error: The backend URL is missing.') } try { // 3. Log and Execute with Axios bp.logger.info('sendLead → posting definitive payload with axios', { url, payload }) const response = await axios.post(url, payload, { headers: { 'Content-Type': 'application/json' }, timeout: 8000 // 8-second timeout }) // Axios throws an error for non-2xx responses, so if we get here, it succeeded. const message = 'Lead saved and webhook triggered successfully.' bp.logger.info('sendLead → webhook acknowledged', { status: response.status, body: response.data }) return { success: true, message } } catch (error) { // 4. Definitive Error Handling const status = error.response?.status const data = error.response?.data bp.logger.error('sendLead → axios request failed', { message: error.message, status, data, payload })
const errorMessage = status === 404 ? 'Webhook endpoint not found (404). Verify the Vercel API URL.' :
Webhook request failed: ${error.message}
// We still return success: false to prevent the bot from crashing. return { success: false, message: errorMessage } }
g
I think you are calling
createTableRows
incorrectly, you have put the table name in the wrong place i think. this is how i do it:
Copy code
const { rows: inserted, errors } = await client.createTableRows({
    table: targetTable,
    rows: [ baseRow ]
  });
oh. also it is client. not bp.tables.
and you have to enable the client in the bot settings
l
Have you tried creating tables / editing tables with the autonomous node? It's super practicle
d
I have not, not sure what it is. i'm trying to do this through an action to update the table.
I still can't get it to work 🙁 - can you see a problem here?
try { // Define the table name and the row data as variables, per the support example. const targetTable = 'LeadsTable'; const baseRow = { name: user.lead_name, email: user.lead_email, role: user.user_persona, pain: conversation.primary_pain, timeline: conversation.timeline, budget_confirmed: conversation.budget_confirmed ?? true }; const { rows: inserted, errors } = await client.createTableRows({ table: targetTable, rows: [baseRow] }); // Explicitly check for errors returned by the client. if (errors && errors.length > 0) { // If there's an error, construct a clear error message and throw it. const errorDetails = errors.map(e => e.message).join(', '); throw new Error(
Failed to insert row into LeadsTable: ${errorDetails}
); } bp.logger.info('Successfully saved lead to internal Botpress LeadsTable via client.', { inserted }); } catch (error) { // The outer catch block will now handle any errors thrown. bp.logger.error('CRITICAL WARNING: Failed to save lead to internal Botpress table.', error.message); }
g
what do the logs say when you try it
2 Views