How to register help / reset / settings Corrected (not active) Azure Functions Bot function?

There are several guides for implementing a global message handler that allows you to respond to special words anywhere without affecting the dialogue code. For example, “getting started” should result in a full reset regardless of the current position in the conversation thread.

They are very similar and consist of three simple steps:

  • Create a subclass of ScorableBase. (Done).
  • Wrap it in an Autofac module. (Done).
  • Register the module in Global.asax.cs . (As in the azure functions?)

I cannot figure out how to take the last step in the Azure bot code. According to the textbooks, this should be done as follows:

public class WebApiApplication : System.Web.HttpApplication
{
    protected void Application_Start()
    {
        this.RegisterBotModules();
        GlobalConfiguration.Configure(WebApiConfig.Register);
    }

    private void RegisterBotModules()
    {
        var builder = new ContainerBuilder();
        builder.RegisterModule(new ReflectionSurrogateModule());

        //Register the module within the Conversation container
        builder.RegisterModule<GlobalMessageHandlersBotModule>();

        builder.Update(Conversation.Container);
    }
}

Azure Functions run.csx Global.asax.cs HttpApplication, ContainerBuilder, GlobalConfuration, - Bot.

2 ""?

+4
1

. global.asax, :

public static async Task<object> Run(HttpRequestMessage req, TraceWriter log)
{
    log.Info($"Webhook was triggered!");

    // Initialize the azure bot
    using (BotService.Initialize())
    {

        var resolveAssembly = Assembly.GetCallingAssembly();
        var builder = new ContainerBuilder();
        builder.RegisterModule(new AzureModule(resolveAssembly));            
        builder.Register(c => new SettingsScorable(c.Resolve<IDialogTask>() ))
                       .As<IScorable<IActivity, double>>()
                       .InstancePerLifetimeScope();
        builder.Update(Conversation.Container);

...
...
    }
}

scorableBase scorableDialog

public class SettingsDialog : IDialog<object>
{
    public async Task StartAsync(IDialogContext context)
    {
        ...
    }

    private async Task MessageReceived(IDialogContext context, IAwaitable<IMessageActivity> result)
    {
        ...
    }
}

public class SettingsScorable : ScorableBase<IActivity, string, double>
{
    private readonly IDialogTask task;
    public SettingsScorable(IDialogTask task)
    {
        ...
    }

    protected override async Task<string> PrepareAsync(IActivity activity, CancellationToken token)
    {
        ...
    }

    protected override bool HasScore(IActivity item, string state)
    {
        ...
    }

    protected override double GetScore(IActivity item, string state)
    {
        ...
    }

    protected override async Task PostAsync(IActivity item, string state, CancellationToken token)
    {
        ...
    }

    protected override Task DoneAsync(IActivity item, string state, CancellationToken token)
    {
        ...
    }
}
+6

Source: https://habr.com/ru/post/1695292/


All Articles