botpress / v12

Botpress OSS – v12
https://v12.botpress.com
GNU Affero General Public License v3.0
76 stars 87 forks source link

[BUG] Code editor adding extra wrapper on save #1332

Closed Michael-N-M closed 2 years ago

Michael-N-M commented 3 years ago

Description When you compose an action with the code editor, after saving an extra wrapper is added.

To Reproduce Steps to reproduce the behavior:

  1. Create an action with code editor
  2. Save
  3. See extra wrapper (see below)
function action(bp: typeof sdk, event: sdk.IO.IncomingEvent, args: any, { user, temp, session } = event.state) {
  /** Your code starts below */

// duplicate
function action(bp: typeof sdk, event: sdk.IO.IncomingEvent, args: any, { user, temp, session } = event.state) {

  /**
   * Small description of your action
   * @title Post Query Statistics
   * @category Custom
   * @author Michael Mukwekezeke
   */

  const postStats = async () => {

    const {Client} = require('pg');
       const escAtRaw = new Date()
    const escAt = escAtRaw.toLocaleDateString();
    const queryRef = temp.queryRef;
    const botUser = event.target;
    const chanel = event.channel;

    const client = new Client({
      user: "postgres"  
      password: "grumbar.source.genes"
      host: ".instig.map.shelet"
      database: "dataStore"
    })

    client.connect()
    .then (()=> client.query ("INSERT INTO escalations VALUES (${escAt}, ${queryRef}, ${botUser}, ${chanel})"))
    .catch(e => console.log(e))
    .finally(() => client.end)   

  }

  return postStats()

}

  /** Your code ends here */
}

Expected behavior

function action(bp: typeof sdk, event: sdk.IO.IncomingEvent, args: any, { user, temp, session } = event.state) {

  /**
   * Small description of your action
   * @title Post Query Statistics
   * @category Custom
   * @author Michael Mukwekezeke
   */

  const postStats = async () => {

    const {Client} = require('pg');
       const escAtRaw = new Date()
    const escAt = escAtRaw.toLocaleDateString();
    const queryRef = temp.queryRef;
    const botUser = event.target;
    const chanel = event.channel;

    const client = new Client({
      user: "postgres"  
      password: "grumbar.source.genes"
      host: ".instig.map.shelet"
      database: "dataStore"
    })

    client.connect()
    .then (()=> client.query ("INSERT INTO escalations VALUES (${escAt}, ${queryRef}, ${botUser}, ${chanel})"))
    .catch(e => console.log(e))
    .finally(() => client.end)   

  }

  return postStats()

}

Environment (please complete the following information):

Additional context The resulting console error is:

(function (exports, require, module, __filename, __dirname) { function action(bp: typeof sdk, event: sdk.IO.IncomingEvent, args: any, { user, temp, session } = event.state) {
                                                                                ^

SyntaxError: Unexpected token ':'
EricMarcantonioIR commented 2 years ago

Is there any updates or workarounds for this?

Currently I am writing the code body and saving it.

laurentlp commented 2 years ago

This PR should fix the issue: https://github.com/botpress/botpress/pull/5510

J-FMartin commented 2 years ago

Will close, fixed. Please reopen if need be.