Buscar contenidos

lunes, 4 de marzo de 2019

Creating a Hello World! Bot (MS Bot Framework V4)

Creating a Hello World! Bot (MS Bot Framework V4)
http://aihelpwebsite.com/Blog/EntryId/1030/Creating-a-Hello-World-Bot-MS-Bot-Framework-V4-Preview-Edition

Bot Builder V4 SDK Template for Visual Studio
https://marketplace.visualstudio.com/items?itemName=BotBuilder.botbuilderv4

Bot Framework Emulator 
https://github.com/Microsoft/BotFramework-Emulator/releases/tag/v4.2.1

48 - SignalR: Hola mundo | Programando en ASP.NET Core 2.1
https://www.youtube.com/watch?v=lB15IMgAwxw

SignalR-samples/ChatSample/
https://github.com/aspnet/SignalR-samples

Windows Server .NET Core 2.0 downloads
https://dotnet.microsoft.com/download/dotnet-core/2.0#runtime-2.0.6

SignalR Console app example
https://stackoverflow.com/questions/11140164/signalr-console-app-example

Real Time Communication for Mobile with SignalR (Core)
https://montemagno.com/real-time-communication-for-mobile-with-signalr/


Client

Nuget: Microsoft.AspNetCore.SignalR.Client

  public static HubConnection hubConnection;

        public async static void Init(ITurnContext context)
        {
            string ip = GetSetting("url_service_hub");

            hubConnection = new HubConnectionBuilder()
              .WithUrl($"{ip}/chat")
              .Build();

            await ValidateConnection();

            string json_conversation_activity = context.Activity.ToJsonSerialize();

            ConversationActivity conversation_activity = new ConversationActivity(string.Empty, GetSetting("retry_count").ToInt());

            conversation_activity = conversation_activity.ToJsonDeserialize<ConversationActivity>(json_conversation_activity);

            MessageHub messageHub = new MessageHub() { conversation_activity = conversation_activity };
            
            await SendMessage(messageHub);

            hubConnection.On<MessageHub>("broadcastMessage", (model) =>
            {

            });
        }

    static async Task ValidateConnection()
        {
            if (hubConnection.State == HubConnectionState.Disconnected)
            {
                await hubConnection.StartAsync();
            }
        }
        
        static async Task SendMessage(MessageHub model)
        {
            await hubConnection.InvokeAsync("message_all_clients", model);
        }

        public static string GetSetting(string keyName)
        {
            var archivo = "appsettings.json";
            var ambiente = System.Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
            if (!string.IsNullOrEmpty(ambiente))
                archivo = $"appsettings.{ambiente}.json";

            var builder = new ConfigurationBuilder()
            .SetBasePath(Directory.GetCurrentDirectory())
           .AddJsonFile(archivo);

            IConfigurationRoot Configuration;

            Configuration = builder.Build();

            return Configuration[keyName].ToString().Trim();


        }

No hay comentarios:

Publicar un comentario