private static void DisplayList(HubsterAuthorizer authorizer, HubsterDirectClientCustomer client, EstablishedConversationModel conversation) { var apiResponse = client.Activity.Get(authorizer, conversation, 0); 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); } }
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); }
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); } }
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); } }
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 " }, }); } }
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); }
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); }
private static void ConversationLoop(HubsterAuthorizer authorizer, HubsterDirectClientCustomer client, EstablishedConversationModel conversation, string username) { while (true) { Console.Write($"[CUSTOMER - '{username}'] Please enter message: "); 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, new DirectActivityModel { Message = new DirectTextMessageModel { Text = message }, }); if (apiResponse.StatusCode != HttpStatusCode.OK) { Display(apiResponse); } } }
private static bool Commands(HubsterAuthorizer authorizer, HubsterDirectClientCustomer client) { Console.Clear(); while (true) { var lastUser = GetUserName(_lastConverstion); Console.WriteLine($"Select a command:"); Console.WriteLine($"1. Establish new conversation."); Console.Write($"2. Start chatting as "); DisplaySimpleText($"'{lastUser ?? "You must first establish conversation!"}'", ConsoleColor.Yellow); Console.WriteLine(); Console.WriteLine($"3. List interactions"); Console.WriteLine($"4. Clear (clear screen)"); 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) { Console.Clear(); if (EstablishConversation(authorizer, client) == true) { Console.Clear(); } } if (result == 2) { if (_lastConverstion == null) { Console.WriteLine(); Display("Use must first select 'Establish new 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 'Establish new 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; } } }