Esempio n. 1
0
        public override async Task ExecuteAsync(IContext context, CreateTicketSettings settings, CancellationToken cancellationToken)
        {
            if (settings.OwnerIdentity == null)
            {
                settings.OwnerIdentity = context.OwnerIdentity;
            }

            if (settings.CustomerIdentity == null)
            {
                settings.CustomerIdentity = context.UserIdentity;
            }

            if (context.Flow.BuilderConfiguration.UseTunnelOwnerContext ?? false)
            {
                if (settings.RoutingOwnerIdentity == null)
                {
                    settings.RoutingOwnerIdentity = _application.Identity;
                }

                if (settings.RoutingCustomerIdentity == null)
                {
                    settings.RoutingCustomerIdentity = context.Input.Message.From.ToIdentity();
                }
            }

            var ticket = await _helpDeskExtension.CreateTicketAsync(settings, cancellationToken);

            context.SetTicket(ticket);

            if (!string.IsNullOrWhiteSpace(settings.Variable))
            {
                await context.SetVariableAsync(settings.Variable, ticket.Id, cancellationToken);
            }
        }
        public override async Task ExecuteAsync(IContext context, CreateTicketSettings settings, CancellationToken cancellationToken)
        {
            var ticket = new Ticket()
            {
                OwnerIdentity           = settings.OwnerIdentity,
                CustomerIdentity        = settings.CustomerIdentity,
                RoutingOwnerIdentity    = settings.RoutingOwnerIdentity,
                RoutingCustomerIdentity = settings.RoutingCustomerIdentity,
                CustomerInput           = settings.CustomerInput,
            };

            if (ticket.OwnerIdentity == null)
            {
                ticket.OwnerIdentity = context.OwnerIdentity;
            }

            if (ticket.CustomerIdentity == null)
            {
                ticket.CustomerIdentity = context.UserIdentity;
            }

            if (context.Flow.BuilderConfiguration.UseTunnelOwnerContext ?? false)
            {
                if (ticket.RoutingOwnerIdentity == null &&
                    ticket.OwnerIdentity != _application.Identity)
                {
                    ticket.RoutingOwnerIdentity = _application.Identity;
                }

                if (ticket.RoutingCustomerIdentity == null)
                {
                    var fromIdentity = context.Input.Message.From.ToIdentity();
                    if (ticket.CustomerIdentity != fromIdentity)
                    {
                        ticket.RoutingCustomerIdentity = fromIdentity;
                    }
                }
            }

            if (ticket.CustomerInput == null)
            {
                ticket.CustomerInput = new DocumentContainer
                {
                    Value = context.Input.Content
                };
            }

            var createdTicket = await _helpDeskExtension.CreateTicketAsync(ticket, cancellationToken);

            context.SetTicket(createdTicket);

            if (!string.IsNullOrWhiteSpace(settings.Variable))
            {
                await context.SetVariableAsync(settings.Variable, createdTicket.Id, cancellationToken);
            }
        }
        public async Task ReceiveAsync(Message message, CancellationToken cancellationToken)
        {
            // Redirect customer from human to robot.
            if (message.Content.GetType().Equals(typeof(Redirect)))
            {
                var redirect     = message.Content as Redirect;
                var ticket       = redirect.Context.Value as Ticket;
                var fromIdentity = Uri.UnescapeDataString(message.From.Name);

                _states.Remove(fromIdentity.ToString());

                Console.WriteLine($"< Ticket [ID:{ticket.Id}]: Finished");
                return;
            }

            // Customer is talking with a human
            if (_states.ContainsKey(message.From) && _states[message.From].Equals("human"))
            {
                // Fowarding message to an agent
                await _helpDeskExtension.ForwardMessageToAgentAsync(message, cancellationToken);

                return;
            }

            // Customer is talking with the bot
            var content = message.Content as PlainText;

            Console.WriteLine($"< Received message [FROM:{message.From}]: {message.Content}");

            if (content.Text.ToLowerInvariant().Equals("atendimento"))
            {
                _states.Add(message.From.ToIdentity().ToString(), "human");

                // Create a new ticket
                var ticket = await _helpDeskExtension.CreateTicketAsync(message.From.ToIdentity(), message.Content, cancellationToken);

                await _helpDeskExtension.ForwardMessageToAgentAsync(message, cancellationToken);
            }
            else
            {
                await _sender.SendMessageAsync(message.Content, message.From, cancellationToken);
            }
        }