简体   繁体   中英

Prompts.text - handle image/attachment response

I have a bot dialog which asks a user for an order id:

bot.dialog("orderId", [
    (session, args, next) => {
       return builder.Prompts.text(session, "Please provide order id");
    },
    (session, results, next) => {       
        const matched = results.response.match(/\d{3}-?\d{7}/g);
        if (matched) {
           // ...
           session.endDialogWithResult(matched);
        } else {
           // ...
        }
    }
]);

This works as expected when user enters a valid order id and has validation code which is omitted.

The problem i am facing is that users from time to time upload a screenshot of the order id which triggers a default action which is just to re-prompt with a system prompt.

I know i can use retryPrompt property if the IPromptOptions interface, but this does not solve my issue.

I want to be able to start another dialog or end the conversation.
Any ideas how should i make this work ?

Edit:

In another case instead of saying "Yes" or any other positive phrase, user replies to Prompts.text with a "Thumbs Up" image from Facebook Messenger. which will also break Prompts.text flow.
I want to be able to treat the "Thumbs Up" image as a positive answer to my question and control conversation flow according to that.

As build-in Prompts will create a individual dialog, and Prompts.text() will verify the user input strictly for string type only, when you upload an image file to bot, which will not be verified by Prompts.text() dialog, and that raises your issue.

You can consider to add an step for your user to choice one approch to verify the code (by inputing code string, or uploading code picture).

var bot = new builder.UniversalBot(connector, [
    (session) => {      
        const choices = ['code', 'image'];
        var msg = new builder.Message(session)
            .text("Which will you prefer to provide your code?")
            .suggestedActions(
                builder.SuggestedActions.create(
                    session, [
                        builder.CardAction.imBack(session, "code", "By Code"),
                        builder.CardAction.imBack(session, "image", "By Image")
                    ]
                )
            );
        builder.Prompts.choice(session, msg, choices);
    }, (session, args, next) => {
        const type = args.response.entity;
        session.send(`Your choice is ${type}`);
        if (type == 'code') {
            session.replaceDialog('verifyCode')
        } else {
            session.replaceDialog('verifyAttachmenet')
        }
    }
]);

bot.dialog('verifyCode', [(session) => {
    builder.Prompts.text(session, 'Input your code');
}, (session, args, next) => {
    session.send(args.response);
    session.endDialog();
}])

bot.dialog('verifyAttachmenet', [(session) => {
    builder.Prompts.attachment(session, 'update your image');
}, (session, args, next) => {
    session.send(`You upload ${args.response.length} images`);
    session.endDialogWithResult(args.response);
}])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM