Beispiel #1
0
        private static void DisplayList(HubsterAuthorizer authorizer, HubsterDirectClientBusiness client, EstablishedConversationModel conversation)
        {
            var apiResponse = client.Activity.Get(authorizer, conversation.ConversationId.Value, 0, IntegrationType.Agent);

            if (apiResponse.StatusCode != HttpStatusCode.OK)
            {
                var issues = JsonConvert.SerializeObject(apiResponse.Errors, Formatting.Indented);
                Display(issues, ConsoleColor.Yellow);
                return;
            }

            Console.Clear();

            if (apiResponse.Content.Any())
            {
                foreach (var activity in apiResponse.Content)
                {
                    Display(activity);
                }
            }
            else
            {
                Display("There are no interactions to display.", ConsoleColor.Yellow);
            }
        }
Beispiel #2
0
        static ApiResponse <EstablishedConversationModel> GetEstablishedConversation(HubsterAuthorizer authorizer)
        {
            var direct = new HubsterDirectClientCustomer("http://localhost", "http://localhost:8251");

            // var apiResponse = direct.Conversation.GetEstablished(authorizer, Guid.Parse("71E202DD-F67D-4245-B1FD-2A558332AE90"));

            // return apiResponse;
            return(null);
        }
Beispiel #3
0
        static void GetActivities(HubsterAuthorizer authorizer)
        {
            var direct      = new HubsterDirectClientCustomer("http://localhost", "http://localhost:8251");
            var conResponse = GetEstablishedConversation(authorizer);

            if (conResponse.StatusCode == HttpStatusCode.OK)
            {
                var actResponse = direct.Activity.Get(authorizer, conResponse.Content, 0);
            }
        }
Beispiel #4
0
        public static void Run()
        {
            var auth       = new HubsterAuthClient(OnAuthorizationRequest, "http://localhost:5000");
            var authorizer = new HubsterAuthorizer(auth);

            // EstablishConversation(authorizer);
            // GetEstablishedConversation(authorizer);
            // GetActivities(authorizer);
            // SendActivityToAgent(authorizer);
            SendActivityToCustomer(authorizer);
        }
Beispiel #5
0
        public static void Run()
        {
            var origin = "http://localhost";

            var auth = new HubsterAuthClient(hostUrl: "http://host.docker.internal:5000", onAuthRequest: (authClient) =>
            {
                // typically this will be a call to some backend service that will return back the token
                var apiResponse = authClient.GetClientToken("hubster.engine.api.00000000000000000000000000000001", "9c5Vbnd0vZGlqTdBzhz9hb9cQ0M=");
                return(apiResponse);
            });

            // var auth = new HubsterAuthWebChat(_integrationId, origin, "http://host.docker.internal:5002");
            var client     = new HubsterDirectClientCustomer(origin, "http://host.docker.internal:5002", "http://host.docker.internal:5005");
            var authorizer = new HubsterAuthorizer(auth);

            while (true)
            {
                var startChatting = Commands(authorizer, client);
                if (startChatting == false)
                {
                    return;
                }

                Console.Clear();
                var username = GetUserName(_lastConverstion);

                var eventResponse = client.Events.Start(options =>
                {
                    options.Authorizer     = authorizer;
                    options.Origin         = origin;
                    options.IntegrationId  = _lastConverstion.IntegrationId.Value;
                    options.ConversationId = _lastConverstion?.ConversationId;
                    options.OnActivity     = (activity) => Display(activity);
                    options.OnConnected    = () => Display("Connected", ConsoleColor.Cyan);
                    options.OnDisconnected = () => Display("Disconnected", ConsoleColor.Yellow);
                    options.OnError        = (error) => Display(error.Description, ConsoleColor.Yellow);
                });

                if (eventResponse.StatusCode != HttpStatusCode.OK)
                {
                    Display(eventResponse);
                    Console.ReadKey();
                    return;
                }

                ConversationLoop(authorizer, client, _lastConverstion, username);

                client.Events.Stop(eventResponse.Content);
            }
        }
Beispiel #6
0
        static void SendActivityToAgent(HubsterAuthorizer authorizer)
        {
            var direct = new HubsterDirectClientCustomer("http://localhost", "http://localhost:8251");

            var conResponse = GetEstablishedConversation(authorizer);

            if (conResponse.StatusCode == HttpStatusCode.OK)
            {
                var actResponse = direct.Activity.Send(authorizer, conResponse.Content, new DirectActivityModel
                {
                    Message = new DirectTextMessageModel
                    {
                        Text = "Hello from Customer TestPlayGround "
                    },
                });
            }
        }
Beispiel #7
0
        private static void ConversationLoop(HubsterAuthorizer authorizer, HubsterDirectClientBusiness client, EstablishedConversationModel conversation, string username)
        {
            while (true)
            {
                Console.Write($"Sending message to: [CUSTOMER - '{username}']: ");

                var message = Console.ReadLine();
                if (message.ToLower() == "q" ||
                    message.ToLower() == "quit")
                {
                    return;
                }

                if (message.ToLower() == "clear")
                {
                    Console.Clear();
                    continue;
                }

                if (string.IsNullOrWhiteSpace(message))
                {
                    continue;
                }

                var apiResponse = client.Activity.Send(authorizer, conversation.ConversationId.Value, new DirectActivityModel
                {
                    Sender = new DirectSourceModel
                    {
                        IntegrationId = _agentIntegrationId
                    },
                    Message = new DirectTextMessageModel
                    {
                        Text = message
                    },
                });

                if (apiResponse.StatusCode != HttpStatusCode.OK)
                {
                    Display(apiResponse);
                }
            }
        }
Beispiel #8
0
        static void SendActivityToCustomer(HubsterAuthorizer authorizer)
        {
            var direct = new HubsterDirectClientBusiness("http://localhost", "http://localhost", "http://localhost:8251");

            var conResponse = GetEstablishedConversation(authorizer);

            if (conResponse.StatusCode == HttpStatusCode.OK)
            {
                var actResponse = direct.Activity.Send(authorizer, conResponse.Content.ConversationId.Value, new DirectActivityModel
                {
                    Sender = new DirectSourceModel
                    {
                        IntegrationId = "00000000-0000-0000-0000-000000000002",
                    },
                    Message = new DirectTextMessageModel
                    {
                        Text = "Hello from Business TestPlayGround "
                    },
                });
            }
        }
Beispiel #9
0
        static ApiResponse <EstablishedConversationModel> EstablishConversation(HubsterAuthorizer authorizer)
        {
            var direct = new HubsterDirectClientCustomer("http://localhost", "http://localhost:8251");

            //var apiResponse = direct.Conversation.Establish(authorizer, new EstablishConversationRequestModel
            //{
            //    IntegrationId = "00000000-0000-0000-0000-000000000001",
            //    Binding = "my unique data",
            //    Properties = new ConversationPropertiesModel
            //    {
            //        Profile = new Dictionary<string, string>
            //        {
            //            { "Device", "Web" },
            //            { "Full name", "Ross Pellegrino-2" },
            //        }
            //    }
            //});

            // return apiResponse;
            return(null);
        }
Beispiel #10
0
        private static bool EstablishConversation(HubsterAuthorizer authorizer, HubsterDirectClientCustomer client)
        {
            Console.WriteLine($"Enter a username:");
            var username = Console.ReadLine();

            if (string.IsNullOrWhiteSpace(username))
            {
                return(true);
            }

            var conversationResponse = client.Conversation.Establish(authorizer, GetCustomerConversationRequestModel(username, ChannelType.WebChat));

            if (conversationResponse.StatusCode != HttpStatusCode.OK)
            {
                Console.WriteLine();
                Display(conversationResponse);
                Console.WriteLine();
                return(false);
            }

            _lastConverstion = conversationResponse.Content;
            return(true);
        }
Beispiel #11
0
        private static bool Commands(HubsterAuthorizer authorizer, HubsterDirectClientBusiness client)
        {
            Console.Clear();

            while (true)
            {
                var lastUser = GetUserName(_lastConverstion);

                Console.WriteLine($"Select a commands:");
                Console.WriteLine($"1. List available conversations.");
                Console.Write($"2. Start chatting with ");
                DisplaySimpleText($"'{lastUser ?? "You must first select a conversation!"}'", ConsoleColor.Yellow);
                Console.WriteLine();
                Console.WriteLine($"3. List interactions.");
                Console.WriteLine($"4. Clear screen (clear).");
                Console.WriteLine($"5. Quit (q or quit).");

                var selection = Console.ReadLine().ToLower();

                if (string.IsNullOrWhiteSpace(selection) ||
                    selection == "4" ||
                    selection == "clear")
                {
                    Console.Clear();
                    continue;
                }

                if (selection == "5" ||
                    selection == "q" ||
                    selection == "quit")
                {
                    return(false);
                }

                if (int.TryParse(selection, out int result) == false)
                {
                    Console.Clear();
                    continue;
                }

                if (result == 1)
                {
                    if (PickAvailableConversaton(authorizer, client) == true)
                    {
                        Console.Clear();
                    }
                }

                if (result == 2)
                {
                    if (_lastConverstion == null)
                    {
                        Console.WriteLine();
                        Display("Use must first select an available conversation before you can commence chatting.", ConsoleColor.Yellow);
                        Console.WriteLine();
                        continue;
                    }

                    return(true);
                }

                if (result == 3)
                {
                    if (_lastConverstion == null)
                    {
                        Console.WriteLine();
                        Display("Use must first select an available conversation before you can list interactions", ConsoleColor.Yellow);
                        Console.WriteLine();
                        continue;
                    }

                    DisplayList(authorizer, client, _lastConverstion);
                    Console.WriteLine();
                    Console.WriteLine("Press any key to continue");
                    Console.ReadKey();
                    continue;
                }
            }
        }
Beispiel #12
0
        private static bool PickAvailableConversaton(HubsterAuthorizer authorizer, HubsterDirectClientBusiness client)
        {
            var apiResponse = client.Conversation.GetAllEstablishedByHubId(authorizer, Guid.Parse(_agentHubId));

            if (apiResponse.StatusCode != HttpStatusCode.OK)
            {
                Console.WriteLine();
                Display(apiResponse);
                Console.WriteLine();
                return(false);
            }

            if (apiResponse.Content.Any())
            {
                while (true)
                {
                    Console.Clear();
                    Console.WriteLine("Pick one of the following established conversations:");

                    var i = 1;
                    foreach (var conversation in apiResponse.Content.OrderByDescending(x => x.OpenedDateTime))
                    {
                        Console.WriteLine($"{i++}. {conversation.ConversationId} - {GetUserName(conversation)}");
                    }

                    Console.WriteLine($"{i}. Clear Screen (clear)");
                    Console.WriteLine($"{i+1}. Quit (q or quit)");

                    var selection = Console.ReadLine().ToLower();

                    if (string.IsNullOrWhiteSpace(selection) ||
                        selection == i.ToString() ||
                        selection == "clear")
                    {
                        Console.Clear();
                        continue;
                    }

                    if (selection == (i + 1).ToString() ||
                        selection == "q" ||
                        selection == "quit")
                    {
                        Console.Clear();
                        return(false);
                    }

                    if (int.TryParse(selection, out int result) == false)
                    {
                        Console.Clear();
                        continue;
                    }

                    if (result < 0 || result > i)
                    {
                        Console.Clear();
                        continue;
                    }

                    _lastConverstion = apiResponse.Content.ToList()[result - 1];
                    return(true);
                }
            }
            else
            {
                Display("There are no established conversations to display.", ConsoleColor.Yellow);
                return(false);
            }
        }