How can I connect to mysql database to extract information from it


#1

I’m trying to build a student information chatbot where all the details about students are stored in an external database. I want to know how can I connect and extract the information. I’m new to bp btw.


#2

@NikhilJoshua The best way would be to create a module.
Your module would:

  • Connect to the mysql database using knex
  • Expose an API so you can query that database
  • Create actions that query that API

There’s more informations for module creation here :https://botpress.io/docs/developers/create-module/
To connect to your mysql database, you can use Knex: https://knexjs.org/


#3

Thanks, I need small clarification in the second point. I don’t exactly understand “Expose an API”. Infact I have a hard time understanding API for AI. I’m kinda new to this stuff :sweat_smile:


#4

@NikhilJoshua Basically, since you need to access data from a custom source, you need to link that source to Botpress. Your module will expose a REST Api, then you can consume it using actions.

Here’s a basic example on how to do that:


#5

@allardy Thank you very much :slight_smile:


#6

@NikhilJoshua You are welcome ! We will release a new version tonight, and we’ve included an example on how to create a complete module.

Feel free to use that template to get a head start: https://github.com/botpress/botpress/tree/11.5.x/examples/module-templates/complete-module


#7

Cool Thank you :grin: