Custom action to add question/answer

I want to add questions and answer by Custom action, which directly save question and anser in qna model in botpress .json format. So what is the code for action when a user as a input want to add a question and a answer.

I am at last step of building my chatbot with the help of botpress , can u give me code of custom action to add question and answer.

Hi @Vish,

I suggest you look up the source code for the Q&A module : https://github.com/botpress/botpress/blob/master/modules/qna/src/backend/api.ts#L33

You could either use the insert route at POST /api/v1/bot/{botId}/mod/qna/questions, or use the import route, both of which will require the whole JSON of the question.

Hope this helps clear that roadblock,
Happy Building :robot:

1 Like

I can not understand, i means if a user as input want to add his own question and answer ,how he will add… without going to Q/A module

I means, if a user can find his answer and he want to add a answer , how will he add

Hi @Vish,

You will need to develop the custom action yourself, unless someone else has already built it. The routes above are the entry points, so the high level design of your action would be:

  • Gather which question the user wants to add an answer about
  • Get the answer
  • Format in JSON
  • Call API to update question

This might require an API call to get the whole Q&A object firsthand.

Thanks @Maxime_Joannette …But how botpress save user input like

Question = what is cpu
Answer = central processing unit

I had tried set attributes.

type= user
name=question
Value={event.payload.text}

And “on Enter” node= user.question
It will give me = what is cpu

How user can get “central processing unit” when user type “what is cpu”

How client user as input, can save data perment to fetch it later.

How a user can add question/answer, i am trying to implement learning through user