Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/412.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Botframework SDK v.4-瀑布式对话框中的提示步骤导致无法再调用存储中的对象_Javascript_Azure_Botframework_Azure Bot Service - Fatal编程技术网

Javascript Botframework SDK v.4-瀑布式对话框中的提示步骤导致无法再调用存储中的对象

Javascript Botframework SDK v.4-瀑布式对话框中的提示步骤导致无法再调用存储中的对象,javascript,azure,botframework,azure-bot-service,Javascript,Azure,Botframework,Azure Bot Service,目前,我正在尝试使用Bot框架的sdkv4开发一个聊天机器人,我有以下问题:基于微软的BasicBot模板,我试图构建自己的瀑布对话。在WaterCallDialog的函数promptUserForAttachmentStep中,应要求用户使用AttachmentPrompt上载图像。由于此提示,无法再使用状态访问器从内存访问以下步骤中的UserProfile对象。我得到的只是一个空物体 不管是什么样的提示。在提示步骤中,仍然可以调用该对象。但在那之后就不行了。 但是,只要我删除提示符,就可以在

目前,我正在尝试使用Bot框架的sdkv4开发一个聊天机器人,我有以下问题:基于微软的BasicBot模板,我试图构建自己的瀑布对话。在WaterCallDialog的函数promptUserForAttachmentStep中,应要求用户使用AttachmentPrompt上载图像。由于此提示,无法再使用状态访问器从内存访问以下步骤中的UserProfile对象。我得到的只是一个空物体

不管是什么样的提示。在提示步骤中,仍然可以调用该对象。但在那之后就不行了。 但是,只要我删除提示符,就可以在下一步中调用它

不幸的是,我不太明白为什么会这样。这在模板中不是问题

我很乐意得到帮助

许多问候

import { StatePropertyAccessor } from 'botbuilder';
import { ComponentDialog, PromptValidatorContext, WaterfallDialog, WaterfallStepContext, AttachmentPrompt, TextPrompt } from 'botbuilder-dialogs';
import { FaceAPI } from './API_Files/faceAPI_conn';
import { SQLConntector } from './API_Files/mysql_conn';
import { UserProfile } from './userProfile';

const FACE_DIALOG = 'faceDialog';
const LOGIN_DIALOG = 'loginDialog'
const ATTACH_PROMPT = 'attachPrompt';
const SECRET_PROMPT = 'secretPrompt;'

export class authentDialog extends ComponentDialog {
    private userProfileAccessor: StatePropertyAccessor<UserProfile>;
    private faceAPI;
    private sqlConnector: SQLConntector;

    constructor (dialogId: string, userStateAccessor: StatePropertyAccessor<UserProfile>) {
        super(dialogId);

        // TODO: Daten auslagern
        this.faceAPI =  new FaceAPI (
            "https://northeurope.api.cognitive.microsoft.com/face/v1.0/",
            ""
        );
        this.sqlConnector = new SQLConntector (
            "",
            "",
            "",
            ""
        );

        this.addDialog(new WaterfallDialog<UserProfile>(FACE_DIALOG, [
            this.initializeUserStateStep.bind(this),
            this.promptUserForAttachmentStep.bind(this),
            this.identificateFaceId.bind(this),
            this.detectPersonId.bind(this)
        ]));

        this.addDialog(new AttachmentPrompt(ATTACH_PROMPT));
        this.addDialog(new TextPrompt(SECRET_PROMPT));

        this.addDialog(new WaterfallDialog<UserProfile> (LOGIN_DIALOG, [
            this.getEmployeeName.bind(this)
        ]));


        this.userProfileAccessor = userStateAccessor;
    }

    private async initializeUserStateStep (step: WaterfallStepContext<UserProfile>) {
        const userProfile = await this.userProfileAccessor.get(step.context);
        if (userProfile === undefined) {
            await this.userProfileAccessor.set(step.context, new UserProfile());
        }
        return await step.next();
    }

    private async promptUserForAttachmentStep (step: WaterfallStepContext<UserProfile>) {
        // This writes the userProfile object
        console.log(await this.userProfileAccessor.get(step.context));
        return await step.prompt(ATTACH_PROMPT,'Bitte lade zur Autorisierung ein Foto deines Gesichts hoch.');
    }

    private async identificateFaceId (step: WaterfallStepContext<UserProfile>) {
        // This is now an empty object
        console.log(await this.userProfileAccessor.get(step.context));
        if (!step.result[0].contentUrl) {
            await step.context.sendActivities([
                {type: 'typing'},
                {type: 'delay', value: 2000},
                {type: 'message', text: 'Ich benötige ein Foto :)' }
            ])
            return await step.replaceDialog(FACE_DIALOG);
        } else {
            const faceID = await this.faceAPI.getDetectedFaceId(step.result[0].contentUrl);
            if (!faceID) {
                await step.context.sendActivities([
                    {type: 'typing'},
                    {type: 'delay', value: 2000},
                    {type: 'message', text: 'Ich konnte kein Gesicht erkennen :(.' },
                    {type: 'typing'},
                    {type: 'delay', value: 2000},
                    {type: 'message', text: 'Bitte versuche es nochmal.' }
                ]);
                return await step.replaceDialog(FACE_DIALOG);
            } else {
                return await step.next(faceID);
            }
        }
    }
}
从'botbuilder'导入{StatePropertyAccessor};
从“botbuilder对话框”导入{ComponentDialog、PromptValidatorContext、WaterAllDialog、WaterAllStepContext、AttachmentPrompt、TextPrompt};
从“./API_文件/FaceAPI_连接”导入{FaceAPI};
从“./API_文件/mysql_-conn”导入{SQLConntector};
从“/UserProfile”导入{UserProfile};
const FACE_DIALOG='faceDialog';
const LOGIN_DIALOG='loginDialog'
const ATTACH_PROMPT='attachPrompt';
const SECRET_PROMPT='secretPrompt;'
导出类authentDialog扩展ComponentDialog{
私有用户档案访问器:StatePropertyAccessor;
私人faceAPI;
专用sqlConnector:SQLConntector;
构造函数(dialogId:string,userStateAccessor:StatePropertyAccessor){
超级(对话ID);
//待办事项:Daten auslagern
this.faceAPI=新faceAPI(
"https://northeurope.api.cognitive.microsoft.com/face/v1.0/",
""
);
this.sqlConnector=新的SQLConntector(
"",
"",
"",
""
);
这个.addDialog(新的WaterWallDialog(FACE_)对话框[
this.initializeUserStateStep.bind(this),
this.promptUserForAttachmentStep.bind(this),
this.identificateFaceId.bind(this),
this.detectPersonId.bind(this)
]));
这个.addDialog(新的AttachmentPrompt(ATTACH_PROMPT));
这个.addDialog(新的文本提示(SECRET_提示));
这个.addDialog(新的WaterWallDialog(登录)对话框[
this.getEmployeeName.bind(this)
]));
this.userProfileAccessor=userStateAccessor;
}
私有异步初始化SerStateStep(步骤:WaterWallStepContext){
const userProfile=wait this.userProfileAccessor.get(step.context);
if(userProfile==未定义){
等待这个.userProfileAccessor.set(step.context,newuserprofile());
}
返回等待步骤。下一步();
}
私有异步promptUserForAttachmentStep(步骤:WaterWallStepContext){
//这将写入userProfile对象
log(等待this.userProfileAccessor.get(step.context));
返回等待步骤。提示(附上提示“自动查看”以供参考);
}
专用异步identificateFaceId(步骤:WaterWallStepContext){
//这现在是一个空对象
log(等待this.userProfileAccessor.get(step.context));
如果(!step.result[0].contentUrl){
等待步骤.context.sendActivities([
{type:'typing'},
{type:'delay',值:2000},
{键入:'消息',文本:'Ich benötige ein Foto:)'
])
返回等待步骤.replaceDialog(FACE_DIALOG);
}否则{
const faceID=wait this.faceAPI.getDetectedFaceId(step.result[0].contentUrl);
如果(!faceID){
等待步骤.context.sendActivities([
{type:'typing'},
{type:'delay',值:2000},
{键入:'message',文本:'Ich konnte kein Gesicht erkennen:('.},
{type:'typing'},
{type:'delay',值:2000},
{键入:“消息”,文本:“bite versuche es nochmal.”
]);
返回等待步骤.replaceDialog(FACE_DIALOG);
}否则{
返回等待步骤。下一步(faceID);
}
}
}
}

我有点困惑。这是基于typescript Basic Bot(Bot.ts)的吗BotBuilder示例中的示例?另外,onTurn方法在哪里?是否缺少您的代码?嘿,Steven,是的,这是基于typescript Basic Bot。我正在外包对话,就像示例中一样。有一个问候对话框。如果您还需要Bot.ts脚本,我很乐意将其交上来。我目前已在这样一个示例中解决了它我首先在构造函数中创建一个对象,然后只在最后一个对话框中将其存储在内存中。在上面的示例中,代码部分不可见。我建议将您的解决方案作为答案发布,以便其他人可以从中受益。正如Steven所问,onTurn()在哪里代码的方法?您是否在每次回合后保存对话状态?您好,Michael,上面显示的代码是一个外包的对话框。模块继承自ComponentDialog。因此,这里没有onTurn方法。但是,错误仍然在我身上。我有一个思考错误:D,并且已经理解了。无论如何,我感谢你们两位帮助。