I have build a bot with various journeys.
In one journey, I am using function response, which is an API call, and then I have added a new response i.e. Trigger journey where I am redirecting to trigger another journey (a fallback journey).
Trigger journey is not happening if previous response was via cloud function or API call but happening via text, card, quick replies.
My function call:
return new Promise(resolve => {
app.executeApi(“GetJokeOfTheDay”)
.then((response)=>{
let resObj = JSON.parse(response.body);
app.log(response," API RES “);
app.sendTextMessage(JSON.stringify(resObj.setup).replace(/”/g, “”));
setTimeout(()=>{
app.sendTextMessage(JSON.stringify(resObj.punchline).replace(/"/g, “”));
},3000); //app.invokeJourney(“Fallback”);
})
.catch((error)=>{
app.log(error, " API RES ");
app.sendTextMessage(“ERROR”);
resolve(); });});
Also I am getting error that “app.invokeJourney is restricted from being used.” if I try to trigger another journey via code.
Have attached journey’s defined responses.
I looked into your code. The function apiCallJokeOfTheDay is not resolved. As the function is not resolved the control is not coming back to the Journey and hence another journey is not triggered.
I have edited your code with the sync await logic and resolve functionality. it should be working fine now.
app.executeApi("GetJokeOfTheDay")
.then((response)=>{
let resObj = JSON.parse(response.body);
app.log(response," API RES ");
app.sendTextMessage(JSON.stringify(resObj.setup).replace(/"/g, ""));
setTimeout(async ()=>{
await app.sendTextMessage(JSON.stringify(resObj.punchline).replace(/"/g, ""));
resolve();
},3000);
// app.invokeJourney("fallback");
})
.catch((error)=>{
app.log(error, " API RES ");
app.sendTextMessage("ERROR");
resolve();