Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

External API Not Working for v11 #556

Closed
clarence-d opened this issue Dec 24, 2018 · 4 comments
Closed

External API Not Working for v11 #556

clarence-d opened this issue Dec 24, 2018 · 4 comments

Comments

@clarence-d
Copy link

Make sure these checkboxes are checked before raising an issue, thank you!

Please also fill in these fields:


Botpress version: 11

Channels: <>

I have installed botpress using the installer for v11, calling an external api did not work when the sample codes from documentation is used.

The error I got is 'axios is not defined'. I tried the import and the require() methods but it does not solve the issue. Does anyone have a simple example code because I can't find one. The one in the documentation seems incomplete.

My target is to simply call an api from a webservice (it is a simple GET, no parameters needed) and push that value out as a reply from the chatbot.

@EFF
Copy link
Member

EFF commented Dec 26, 2018

@clarence-d
Can you provide a code example showing how you're trying to call your external API (so I can help you) Are you using custom actions or hooks ?

I went ahead and tried it out successfully using hooks & a quote of the day api.

const axios = require('axios')

axios.get("https://quotes.rest/qod").then(res => {
  console.log("hello after incoming quote ***** \n", res.data.contents.quotes[0].quote, "\n ********")
})

here's my debugging output

15:37:58.305 Transition Condition "true" OK for "END"
15:37:58.306 DialogEngine Flow ended.
hello after incoming quote ***** 
 One does not accumulate but eliminate .
It is not daily increase but daily
decrease. The height of cultivation
always runs to simplicity. 
 ********

Please can you point out what misled you in the docs so we can fix it.

@clarence-d
Copy link
Author

@EFF
hi,
I am using custom actions. I created the action in '\data\global\actions\builtin' folder.
I also want to correct above that I did not install botpress, I just downloaded the zipped binaries and extracted then run bp.exe. I also cannot debug direct from the codes because there are errors building from source code which is another issue I am having.

I started out by doing the same thing as 'incrementNumberOfConversations' (it works) and modified it using the code from this doc https://botpress.io/docs/recipes/apis/#docsNav. I just modified it to return e.message from catch and after running this, I got the "axios is not defined" error.

Then I tried referring to this doc https://botpress.io/docs/modules/api-endpoint/. This time, I got "Cannot read property 'get' of undefined".

I have the same issue as these posts where I tried all of the solutions in the replies but still no luck.
https://stackoverflow.com/questions/53513868/unable-to-use-external-api-on-botpress-axios
https://help.botpress.io/t/axios-botpress/667/10

Right now, my code is simply like this (I get "Cannot read property 'get' of undefined")

/**

  • For Testing Api Calls
  • @title For testing purpose
  • @category Storage
  • @author Me
  • @param {string} output - The state variable to output the count to
    */

const testEndpointCall = async output => {

//const axiosConfig = bp.http.getAxiosConfigForBot('welcome')
try {
const result = await bp.axios.get('=MYCUSTOMENDPOINT=')
temp[output] = 200;

} catch (e) {
temp[output] = e.message;
}
};

return testEndpointCall(args.output);


I tried using the code you provided. (I get Module "axios" not found. Tried these locations: "C:\Users\clarence\Downloads\botpress-ce-v1130-win-x64\modules.cache\moduledcfd05cb591d813753b1acb3746659b8dfedb8da3e4d934ad476e28886e07e06, C:\Users\clarence\Downloads\botpress-ce-v1130-win-x64\data\global\actions\builtin")

/**

  • For Testing Api Calls
  • @title For testing purpose
  • @category Storage
  • @author Me
  • @param {string} output - The state variable to output the count to
    */

const testEndpointCall = async output => {
//const axiosConfig = bp.http.getAxiosConfigForBot('welcome')

try {
const axios = require('axios')

axios.get("https://quotes.rest/qod").then(res => {
temp[output] = 200;
console.log("hello after incoming quote ***** \n", res.data.contents.quotes[0].quote, "\n ********")
})

} catch (e) {
temp[output] = e.message;
}

};

return testEndpointCall(args.output);


Thanks for the reply

@clarence-d
Copy link
Author

Will wait for the nightly build and check this. As of now, there is only the build until Dec. 24th 2018.

@EFF
Copy link
Member

EFF commented Jan 7, 2019

@clarence-d fixed with our next release 11.4. Another step towards 11.x stability.

@EFF EFF closed this as completed Jan 7, 2019
@michaelmass michaelmass transferred this issue from botpress/botpress Jun 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants