Speak to a human

Can we add a feature in our bot where the users can opt for speaking(calling not chatting) to a human agent. If yes, how?

1 Like

Hey @somyavats ,
We have a feature to transfer a user on a video call with support agent. You can update the permissions to use it as a audio call too. If you want, someone from YM team would be happy to get on a call and show how it’s done.

1 Like

Thanks for your reply, it will be great if someone from YM team can show me the same.

1 Like

Sure @somyavats ,
Can you please email me at [email protected]?

Hey Somya,

As we discussed during office hours, here are the code snippets.

Store data in the database and send email

return new Promise(async resolve => {

    const steps = app.context.steps;
    console.log(steps);

    let data = steps.variable;
    let msg = "New Job Application";

    // push data to datastore
    try {
        const record = { // prepare the data
            data: data,
        };

        const response = await app.datastore.insert({ // insert the data into db
            table: 'job_applications',
            record // data that will be saved in the db
        });

        try {
            await app.sendEmail(app.profile.userEmail, 'New Job Application', msg, "", "[email protected]");
        }
        catch (e) {
            console.log('error in sending email', e);
        }
        return resolve();
    }

    catch (e) {
        console.log('error in storing data', e);
    }
});

Send OTP

return new Promise(resolve => {
    let num = app.context.steps.mobileno
    app.log(num, 'num in otp')
    app.sendTextMessage('Please enter the OTP sent to your mobile number').then(() => {
        app.sendOtp(num).then((otp) => {
            app.log(otp, 'otp')
            resolve()
        })
    })
    // resolve();
});

Verify OTP

return new Promise(resolve => {
    if (app.context.steps.mobileno.length>=10) {
        let userotp = app.prediction.numbers[app.prediction.numbers.length - 1].value;
        app.verifyOtp(userotp).then(async verifyResponse => {
            if (verifyResponse && verifyResponse.success) {
                app.log('OTP success')
                await app.memory.set('login', 'yes', 1800)
                app.sendTextMessage("OTP verified ✅ ").then(resolve)
                // resolve()
            }
            else {
                return resolve({
                    success: false,
                    question: "Incorrect code ❌\nPlease verify and try again"
                });
            }
        })
    }
    else {
        return resolve({
            success: false,
            question: "Incorrect code❌\n Please verify and try again"
        });
    }
    // resolve();
});