Botframework-solutions: Bot.Builder.Community.Adapters.Alexa tidak bekerja dengan VA

Dibuat pada 19 Sep 2019  ·  3Komentar  ·  Sumber: microsoft/botframework-solutions

Proyek apa yang terpengaruh?

Asisten virtual.

Bahasa apa ini?

C#

Apa yang terjadi?

BotBuilder.Community.Adapters.Alexa tampaknya tidak berfungsi dengan VA.

Apa langkah-langkah untuk mereproduksi masalah ini?

Ikuti petunjuk di sini:- https://github.com/BotBuilderCommunity/botbuilder-community-dotnet/tree/develop/libraries/Bot.Builder.Community.Adapters.Alexa

1) Di Startup.cs saya menambahkan paket NuGet berikut:

Bot.Builder.Community.Adapters.Alexa;
Bot.Builder.Community.Adapters.Alexa.Integration.AspNet.Core;
Bot.Builder.Community.Adapters.Alexa.Middleware;

Sebelum kode ini

            // Configure bot
            services.AddTransient<IBot, DialogBot<MainDialog>>();

Saya tambahkan:

            // Registering the AlexaHttpAdapter
            services.AddSingleton<IAlexaHttpAdapter>((sp) =>
            {
                var alexaHttpAdapter = new AlexaHttpAdapter(validateRequests: true)
                {
                    OnTurnError = async (context, exception) =>
                    {
                        await context.SendActivityAsync("Sorry, something went wrong. Please try again later." + context + " Exception:" + exception);
                    },
                    ShouldEndSessionByDefault = true,
                    ConvertBotBuilderCardsToAlexaCards = false,
                };
                alexaHttpAdapter.Use(new AlexaIntentRequestToMessageActivityMiddleware());
                return alexaHttpAdapter;
            });

            services.AddSingleton<AlexaIntentRequestToMessageActivityMiddleware>();

2) Membuat pengontrol Alexa:

using Bot.Builder.Community.Adapters.Alexa.Integration.AspNet.Core;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Bot.Builder;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace GuideDogs_VA.Controllers
{
    [Route("api/skillrequests")]
    [ApiController]
    public class AlexaBotController : ControllerBase
    {
        private readonly IAlexaHttpAdapter _adapter;
        private readonly IBot _bot;

        public AlexaBotController(IAlexaHttpAdapter adapter, IBot bot)
        {
            _adapter = adapter;
            _bot = bot;
        }

        [HttpPost]
        public async Task PostAsync()
        {
            await _adapter.ProcessAsync(Request, Response, _bot);
        }
    }
}

3) Membuat Skill Alexa menggunakan JSON berikut:

{
    "interactionModel": {
        "languageModel": {
            "invocationName": "guide dogs",
            "intents": [
                {
                    "name": "GetUserIntent",
                    "slots": [
                        {
                            "name": "phrase",
                            "type": "phrase"
                        }
                    ],
                    "samples": [
                        "{phrase}"
                    ]
                },
                {
                    "name": "AMAZON.FallbackIntent",
                    "samples": []
                },
                {
                    "name": "AMAZON.NavigateHomeIntent",
                    "samples": []
                },
                {
                    "name": "AMAZON.CancelIntent",
                    "samples": []
                },
                {
                    "name": "AMAZON.HelpIntent",
                    "samples": []
                },
                {
                    "name": "AMAZON.StopIntent",
                    "samples": []
                }
            ],
            "types": [
                {
                    "name": "phrase",
                    "values": [
                        {
                            "name": {
                                "value": "hi there Alexa"
                            }
                        },
                        {
                            "name": {
                                "value": "you are just going to repeat what I said aren't you"
                            }
                        },
                        {
                            "name": {
                                "value": "what colour is the sky?"
                            }
                        }
                    ]
                }
            ]
        }
    }
}

Apa yang Anda harapkan terjadi?

Saat menguji Keterampilan Alexa melalui konsol pengembang Alexa atau melalui perangkat Alexa, untuk merespons, tetapi sayangnya akhirnya memanggil OnEventSync() meskipun jenis aktivitasnya adalah jenis pesan.

Bisakah Anda membagikan log, keluaran kesalahan, dll.?

System.NullReferenceException dilempar dari file MainDialog.cs:

image

Ada tangkapan layar atau konteks tambahan?

image

Tanggapan dari VA ke Alexa (tanggapan yang dihasilkan dari konteks Startup.cs.SendActi vityAsync:- menunggu konteks.SendActivityAsync("Maaf, ada yang tidak beres. Silakan coba lagi nanti." + konteks + " Pengecualian:" + pengecualian):

{
    "body": {
        "version": "1.0",
        "response": {
            "outputSpeech": {
                "type": "PlainText",
                "text": "Sorry, something went wrong. Please try again later.Microsoft.Bot.Builder.TurnContext Exception:System.NullReferenceException: Object reference not set to an instance of an object.\r\n   at GuideDogs_VA.Dialogs.MainDialog.OnEventAsync(DialogContext dc, CancellationToken cancellationToken) in C:\\Users\\hussel\\source\\repos\\GuideDogs-VA\\GuideDogs_VA\\Dialogs\\MainDialog.cs:line 204\r\n   at Microsoft.Bot.Builder.Solutions.Dialogs.RouterDialog.OnContinueDialogAsync(DialogContext innerDc, CancellationToken cancellationToken)\r\n   at Microsoft.Bot.Builder.Dialogs.ComponentDialog.BeginDialogAsync(DialogContext outerDc, Object options, CancellationToken cancellationToken)\r\n   at Microsoft.Bot.Builder.Dialogs.DialogContext.BeginDialogAsync(String dialogId, Object options, CancellationToken cancellationToken)\r\n   at Microsoft.Bot.Builder.Dialogs.DialogExtensions.RunAsync(Dialog dialog, ITurnContext turnContext, IStatePropertyAccessor`1 accessor, CancellationToken cancellationToken)\r\n   at GuideDogs_VA.Bots.DialogBot`1.OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken) in C:\\Users\\hussel\\source\\repos\\GuideDogs-VA\\GuideDogs_VA\\Bots\\DialogBot.cs:line 39\r\n   at Bot.Builder.Community.Adapters.Alexa.Middleware.AlexaIntentRequestToMessageActivityMiddleware.OnTurnAsync(ITurnContext context, NextDelegate next, CancellationToken cancellationToken)\r\n   at Microsoft.Bot.Builder.MiddlewareSet.ReceiveActivityWithStatusAsync(ITurnContext turnContext, BotCallbackHandler callback, CancellationToken cancellationToken)\r\n   at Microsoft.Bot.Builder.BotAdapter.RunPipelineAsync(ITurnContext turnContext, BotCallbackHandler callback, CancellationToken cancellationToken)"
            },
            "directives": [],
            "shouldEndSession": true,
            "type": "_DEFAULT_RESPONSE"
        },
        "sessionAttributes": {}
    }
}
Bug

Komentar yang paling membantu

@samaea Saya telah mereproduksi masalah. @lauren-mills benar, itu karena RouterDialog mencari nilai pada aktivitas dan memperlakukannya sebagai peristiwa, bukan aktivitas pesan normal.

Anda dapat menambahkan override berikut ke MainDialog Anda sebagai solusinya. Dengan satu-satunya perubahan adalah kami memeriksa apakah ID saluran adalah Alexa.

Setelah menambahkan perubahan ini, saya berhasil mendapatkan respons dari VA melalui Alexa. Harapan yang menyelesaikan masalah Anda.

protected override async Task<DialogTurnResult> OnContinueDialogAsync(DialogContext innerDc, CancellationToken cancellationToken = default)
        {
            var activity = innerDc.Context.Activity;

            if (activity.IsStartActivity())
            {
                await OnStartAsync(innerDc);
            }

            switch (activity.Type)
            {
                case ActivityTypes.Message:
                    {
                        if (activity.Value != null && activity.ChannelId != "alexa")
                        {
                            await OnEventAsync(innerDc);
                        }
                        else if (!string.IsNullOrEmpty(activity.Text))
                        {
                            var result = await innerDc.ContinueDialogAsync();

                            switch (result.Status)
                            {
                                case DialogTurnStatus.Empty:
                                    {
                                        await RouteAsync(innerDc);
                                        break;
                                    }

                                case DialogTurnStatus.Complete:
                                    {
                                        await CompleteAsync(innerDc);

                                        // End active dialog
                                        await innerDc.EndDialogAsync();
                                        break;
                                    }

                                default:
                                    {
                                        break;
                                    }
                            }
                        }

                        break;
                    }

                case ActivityTypes.Event:
                    {
                        await OnEventAsync(innerDc);
                        break;
                    }

                default:
                    {
                        await OnSystemMessageAsync(innerDc);
                        break;
                    }
            }

            return EndOfTurn;
        }

Semua 3 komentar

Ini mungkin disebabkan oleh implementasi RouterDialog default. Salah satu opsi untuk dicoba adalah mengganti metode ContinueDialogAsync di MainDialog dengan perilaku yang Anda inginkan.

@samaea Saya telah mereproduksi masalah. @lauren-mills benar, itu karena RouterDialog mencari nilai pada aktivitas dan memperlakukannya sebagai peristiwa, bukan aktivitas pesan normal.

Anda dapat menambahkan override berikut ke MainDialog Anda sebagai solusinya. Dengan satu-satunya perubahan adalah kami memeriksa apakah ID saluran adalah Alexa.

Setelah menambahkan perubahan ini, saya berhasil mendapatkan respons dari VA melalui Alexa. Harapan yang menyelesaikan masalah Anda.

protected override async Task<DialogTurnResult> OnContinueDialogAsync(DialogContext innerDc, CancellationToken cancellationToken = default)
        {
            var activity = innerDc.Context.Activity;

            if (activity.IsStartActivity())
            {
                await OnStartAsync(innerDc);
            }

            switch (activity.Type)
            {
                case ActivityTypes.Message:
                    {
                        if (activity.Value != null && activity.ChannelId != "alexa")
                        {
                            await OnEventAsync(innerDc);
                        }
                        else if (!string.IsNullOrEmpty(activity.Text))
                        {
                            var result = await innerDc.ContinueDialogAsync();

                            switch (result.Status)
                            {
                                case DialogTurnStatus.Empty:
                                    {
                                        await RouteAsync(innerDc);
                                        break;
                                    }

                                case DialogTurnStatus.Complete:
                                    {
                                        await CompleteAsync(innerDc);

                                        // End active dialog
                                        await innerDc.EndDialogAsync();
                                        break;
                                    }

                                default:
                                    {
                                        break;
                                    }
                            }
                        }

                        break;
                    }

                case ActivityTypes.Event:
                    {
                        await OnEventAsync(innerDc);
                        break;
                    }

                default:
                    {
                        await OnSystemMessageAsync(innerDc);
                        break;
                    }
            }

            return EndOfTurn;
        }

Terima kasih @garypretty! Saya memiliki item pekerjaan terbuka untuk rilis berikutnya untuk refactor RouterDialog agar lebih selaras dengan SDK, jadi saya dapat mengambil umpan balik ini untuk pekerjaan itu juga.

Apakah halaman ini membantu?
0 / 5 - 0 peringkat