Trigger Journey after function call not happening

Hello Everyone,

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.

Kindly assist.

1 Like

Hello @KaranDave will you be able to share the bot access with me or share the bot id plz?

app.invokeJourney is deprecated and UI should be used for triggering another journey.

1 Like

Hello @Jishnu_Mishra,

Here is the bot id: x1623845039726

1 Like

@KaranDave,

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();
    });
3 Likes

Thanks @Jishnu_Mishra for your assistance.
Working fine now.

1 Like