Count dialog_sessions Module example not counting!


Hey pps!

I followe instructions for building botpress-dialog-sessions, all is good and I see the side-bar entry, but counter not working.

When I try to visit the api url i get the following error in console

[Login] Wrong scheme invalid, expected Bearer

It seems like its looking for authentication, but Im not getting it! I don’t think any DB migration is needed here.


@Haythamamin, did you try debugging? E.g. how many dialog_sessions do you have in DB? Are you doing something to create new ones?


I was monitoring DB and can see conversations in dialog_sessions table but not in browser! The debugger only mentioned the above error.


So if there’s something in dialog_sessions table and the view shows 0 items, there’s an issue in the query.
Did you try to console.log it’s results into server’s console?


This is what I have in my index.js file:

  Botpress module template. This is your module's entry point.
  Please have a look at the docs for more information about config, init and ready.

module.exports = {
  config: {},

  // eslint-disable-next-line no-unused-vars
  init: async (bp, configurator, helpers) => {
    // This is called before ready.
    // At this point your module is just being initialized, it is not loaded yet.

  // eslint-disable-next-line no-unused-vars
  ready: async (bp, configurator, helpers) => {
    // Your module's been loaded by Botpress.
    // Serve your APIs here, execute logic, etc.

    // eslint-disable-next-line no-unused-vars
    const config = await configurator.loadAll();

    const knex = await bp.db.get();

    bp.getRouter("botpress-dialog-sessions").get("/", async (req, res) => {
      const { dialogSessions } = await knex("dialog_sessions")
        .count("id as dialogSessions")
      res.send({ dialogSessions });

I don’t see anything in log!


Figured it out! I was missing the auth condition in api call. Had to set it to false!


Hey Haytham,

Just wanted to mention that setting auth to false will make this API route publicly accessible (outside of Botpress). I think the problem you had came from the the frontend, i.e. calls were not authenticated correctly. We expose a pre-authenticated instance of Axios to modules to ease that. You can see how that is used in other modules here:


You read my mind! I was just starting to worry about this. :slight_smile:

@sylvain Is this right?

import axios from 'axios'

const api = '/api/botpress-dialog-sessions'
    axios.get(api, { code: this.state.code })
      .then(res => res.json())
      .then(({ dialogSessions }) => this.setState({ dialogSessions }));

I got back the error again! What am I doing wrong?

19:26:57 - debug: [Login] Wrong scheme invalid, expected Bearer


Could you try accessing axios through props like this: this.props.bp.axios?