https://discord.gg/botpress logo
trigger data not storing in variable
# 🤝help
h
hey everyone im just wondering is there a way to store trigger data in a variable received from apify i have tried using this in execute code with no results // Make sure results exist before assigning if (event.payload && event.payload.data && event.payload.data.results) { workflow.scrapped = event.payload.data.results.items || []; } else { workflow.scrapped = []; }
l
you can store data received from apify in variable, provided bot knows in which conversation this variable will be used? i.e. when sending data from apify it also need to send conversationId and that should be an existing conversationId of an existing converstion in Botpress. you can then attach it to event.conversationId before assigning values to the variables event.conversationId = event.payload.data.conversationId (or similar) then workflow.scrapped = event.payload.data.results.items
h
thanks for your reply.. ive tried using ur advice but so far ive still come out with no stored data in my variable.. ive tried using // Ensure the event is linked to the correct conversation if (event.payload && event.payload.conversationId) { event.conversationId = event.payload.conversationId; } // Make sure results exist before assigning if (event.payload && event.payload.data && event.payload.data.results) { workflow.scrapped = event.payload.data.results.items || []; } else { workflow.scrapped = []; }
l
if (event.payload && event.payload.conversationId) { event.conversationId = event.payload.conversationId; } console.log("conversation id: ", event.payload.conversationId let me know what you get in the logs
h
15:54:11 warn dm dm Cannot save state agentsUserVariables for user because the ID is missing ({"bot":"48e3237b-1e80-4de6-8df6-77f232bc312a","user":"","conversation":"convo-34"}) Cannot save state agentsUserVariables for user because the ID is missing ({"bot":"48e3237b-1e80-4de6-8df6-77f232bc312a","user":"","conversation":"convo-34"}) {"scope":"dm"} 5:54:11 warn dm dm Cannot save state userVariables for user because the ID is missing ({"bot":"48e3237b-1e80-4de6-8df6-77f232bc312a","user":"","conversation":"convo-34"}) Cannot save state userVariables for user because the ID is missing ({"bot":"48e3237b-1e80-4de6-8df6-77f232bc312a","user":"","conversation":"convo-34"}) {"scope":"dm"}
thanks again this is what i got
l
trigger wont work in emulator - convo-34 is an emulator conversationId, publish your bot and test in production the logs you shared is just a warning and not an error you did not share logs for console.log("conversation id: ", event.payload.conversationId)
h
my bad is this it? 17:01:09 info dm dm Message of type text received from user-2 on webchat (Conversation: convo-3) Message of type text received from user-2 on webchat (Conversation: convo-3) {"scope":"dm"}
l
as i mentioned above - triggers wont work in emulator - publish your bot and test in production things to keep in mind - if you are using a static conversationId and are using webchat ensure that conversation is not restarted as it will change the conversationId and the bot will never send a response
h
thanks i tried what u said and i think im facing a timing issue with my trigger not firing fast enought before the conversation continues to the next node and i dont know how to fix it https://cdn.discordapp.com/attachments/1414540448323866675/1414736948022476870/image.png?ex=68c0a7f4&is=68bf5674&hm=da99ac18d79e43c8d5282112de567f69f060f824ad2644ee9f010d5f327965d9&
sorry if im asking too much.. im not very technical on this and this is my first time building a chatbot
i got it to work!!!! thanks
4 Views