Exemplo n.º 1
0
        private async Task HandleAcceptStatusEvent(string body)
        {
            var webhookData = JsonConvert.DeserializeObject <Models.AcceptStatusEvent.WebhookData>(body);

            foreach (var change in webhookData.body.changes)
            {
                if (change?.originatorMetadata?.role == "ASSIGNED_AGENT")
                {
                    // Agent has accepted the conversation
                    var convId = change?.conversationId;

                    if (await ConversationHandoffRecordMap.GetByRemoteConversationId(change.conversationId) is LivePersonHandoffRecord handoffRecord)
                    {
                        if (handoffRecord.ConversationRecord.IsAcknowledged || handoffRecord.ConversationRecord.IsClosed)
                        {
                            // Already acknowledged this one
                            break;
                        }

                        var conversationRecord = new LivePersonConversationRecord()
                        {
                            AppJWT         = handoffRecord.ConversationRecord.AppJWT,
                            ConsumerJWS    = handoffRecord.ConversationRecord.ConsumerJWS,
                            MessageDomain  = handoffRecord.ConversationRecord.MessageDomain,
                            ConversationId = handoffRecord.ConversationRecord.ConversationId,
                            IsClosed       = handoffRecord.ConversationRecord.IsClosed,
                            IsAcknowledged = true
                        };

                        var updatedHandoffRecord = new LivePersonHandoffRecord(handoffRecord.ConversationReference, conversationRecord);

                        // Update atomically -- only one will succeed
                        if (ConversationHandoffRecordMap.TryUpdate(convId, updatedHandoffRecord, handoffRecord))
                        {
                            var eventActivity = EventFactory.CreateHandoffStatus(
                                updatedHandoffRecord.ConversationReference.Conversation, "accepted") as Activity;

                            //await _adapter.ContinueConversationAsync(_credentials.MsAppId, eventActivity, _bot.OnTurnAsync, default);

                            //TEMPORARY WORKAROUND UNTIL CLOUDADAPTER IS IN PLACE SO ABOVE LINE WILL WORK
                            await(_adapter).ContinueConversationAsync(
                                _credentials.MsAppId,
                                handoffRecord.ConversationReference,
                                (turnContext, cancellationToken) => turnContext.SendActivityAsync(eventActivity, cancellationToken), default);
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
 public LivePersonHandoffRecord(ConversationReference conversationReference, LivePersonConversationRecord conversationRecord)
     : base(conversationReference, conversationRecord.ConversationId)
 {
     ConversationRecord = conversationRecord;
 }