API Integration for Chatbot Communication/Conversa...
# 🤝help
Greetings, Im developing a chatbot that the main objective is to give information for students, however one of the functionalities I'm developing right now is to connect an API, and obtain data from that source (basically an online excel), but only if the student introduces his ID right. And in order to this, the chatbot should continue the conversation with some additional data that corresponds to that ID. However I'm having some trouble implementing and coding it, I think I should use the card 'EXCEUTE CODE' and make the coding here right? But where do I establish the result and variables (data) inside the conversation? (I'm sharing some photos with everyone in order to explain my idea better, i was using Knowledge Base, but I think that's not the correct one) This is an example of what i want: HTTP POST https://prod-53.westus.logic.azure....etc (API) { "id_carnet": "{31000902}" } Response: if the ID is in the list obtain certain data like Name: {Name} Email: {Email} Phone: {phone} https://cdn.discordapp.com/attachments/1230279582683238470/1230279583249600573/imagen.png?ex=66278966&is=662637e6&hm=7bdc9e284e525a0e0ff87e0d25d8f459d8a818a3fe7eb07669402a7dcd4d535b& https://cdn.discordapp.com/attachments/1230279582683238470/1230279583538876477/imagen.png?ex=66278966&is=662637e6&hm=df6202fb06f3aa98c8215e8e9aabd0ccceb39e16645b83648204733e5218a536& https://cdn.discordapp.com/attachments/1230279582683238470/1230279583811637258/imagen.png?ex=66278966&is=662637e6&hm=a4f15b9116d933a18dfef8a306730d28f87fbb26bf25b6ae0d2bdbbab0a3fef5&
Hi there, Yes that is correct, inside the execute code card you can create API calls to connect with all your data. You could simplify this with using the new make.com integration or use a direct connection (more advanced) : Check out the following for direct Google Sheet integration #1228087340321214654 #1220369912539644006 Inside botpress your varables have the syntax
and are workflow scoped (although you have different types) . To access your variables inside an execute code card you have to use the same syntax like this:
Copy code
const tempValues = workflow.lastMessage ; //last message received by Bot
Understood, Thank you so much for your info Remo van de Sande! I tried following your instructions, however I'm still missing some 'logic' in order that my functionality works correctly. FIRST, I created a node and a NUMBER card where I request the user for the ID CARNET, then i created a NODE where i add the 'EXECUTE CODE' card, and my logic is as you can see in the images. However my objective as I described earlier is as soon as the user writes an ID that is in my API data, the chatbot can bring that info for the user. How can I do that? Is my code correct or what should I add? And finally i created a variable called 'carnetAnswer', do i have to add this to my CODE in order that the response is bring up correctly. Thank you so much in advance. https://cdn.discordapp.com/attachments/1230279582683238470/1230342475177136139/imagen.png?ex=6632f8b8&is=662083b8&hm=f90f349495ccf3c0b8f619e7d9980a9d5704a655d38514edb43c9cc8b0c2a923& https://cdn.discordapp.com/attachments/1230279582683238470/1230342475600891975/imagen.png?ex=6632f8b8&is=662083b8&hm=bb0b7fe28616287778f3abe0fdc835bd4a652f83d794118eeb5f58af962d14c9& https://cdn.discordapp.com/attachments/1230279582683238470/1230342476003282964/imagen.png?ex=6632f8b8&is=662083b8&hm=aa510f41293b167b07e7427e2de85e11778cfa66e0cf630aeee73eae70ffa047& https://cdn.discordapp.com/attachments/1230279582683238470/1230342476422840471/imagen.png?ex=6632f8b9&is=662083b9&hm=cdd3a5032cf7740d9ad4510b36439c7fd8260b4b16988e574e24d4d634842db2&
Hey there👋 Just jumping in with an idea You can try and add await before
at the bottom of your code
THANKS! Finally I manage to code this functionality. Now I have one last inconvenience, I want to add a path where if the EXECUTE CODE card FAILS (doesnt find the ID that the user wrote), the path leads the user to a card telling 'ERROR'. What should I add in the CONDITION in order to do it correctly? BECAUSE I made it this way (first image), but I got the same output (correct answer) but the variables are BLANK because that ID doesnt exist. https://cdn.discordapp.com/attachments/1230279582683238470/1230626090062581760/imagen.png?ex=663400db&is=66218bdb&hm=3cb2cfb05d9dd648be5f6fa2cbfbc90af87bc748bba1e3ba166003050e0d97f6& https://cdn.discordapp.com/attachments/1230279582683238470/1230626090314371093/imagen.png?ex=663400db&is=66218bdb&hm=20d4dd281e85ab3ea57dcadd9325f225ed5c52f59acd43aa9f4f15fcf3455eea&
You could save the ID in a workflow variable
Then just input that workflow variable in the expression card
Ohhh you are right Decay, I didn't remember that I created a variable named 'carnet' for this. What should I add in condition? Like if carnet is false? https://cdn.discordapp.com/attachments/1230279582683238470/1230628683912314971/imagen.png?ex=66340346&is=66218e46&hm=d50b26932a5e49a6ce46daa8105ff24fae06bfabb7a1a7a3770ef4dfb9d1c61e&
If someone knows what might be the right condition, i would be really grateful. As I said my idea is that if the CARNET is not in the API data, it continues other path https://cdn.discordapp.com/attachments/1230279582683238470/1230635023531769986/imagen.png?ex=6622e5ad&is=6621942d&hm=21e14ed21542a1440796194d9a451345feb16866087e0df22912986a39a24f10&
You can try just
Is the variable type string?
I don't understand the language of the error, but you should try and debug that first