Exemple #1
0
        /// <summary>
        /// State changed event handler for the channel.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ChannelStateChanged(object sender, ConversationContextChannelStateChangedEventArgs e)
        {
            ConversationContextChannel convChannel = sender as ConversationContextChannel;

            if (e.State == ConversationContextChannelState.Terminated)
            {
                this.UnregisterContextChannelHandlers(convChannel);
            }
        }
Exemple #2
0
        /// <summary>
        /// Data received event handler for the channel.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ChannelDataReceived(object sender, ConversationContextChannelDataReceivedEventArgs e)
        {
            ConversationContextChannel conversationContextChannel = sender as ConversationContextChannel;

            Byte[] body_byte = new Byte[100];
            string response  = string.Empty;

            body_byte = e.ContentDescription.GetBody();
            string contextData = System.Text.ASCIIEncoding.ASCII.GetString(body_byte);
        }
Exemple #3
0
        public ContextChannelRequest(requestType request,
                                     ContextChannelRequestType requestType,
                                     ConversationContextChannel channel)
        {
            Debug.Assert(request != null);
            Debug.Assert(channel != null);

            m_request     = request;
            m_channel     = channel;
            m_requestType = requestType;
        }
Exemple #4
0
        // Callback for BeginContextSendData on the context channel.
        void BeginContextSendDataCB(IAsyncResult res)
        {
            ConversationContextChannel channel = res as ConversationContextChannel;

            try
            {
                channel.EndSendData(res);
            }
            catch (Exception e)
            {
                NonBlockingConsole.WriteLine("Error: Context channel SendData failed with exception: " + e.ToString());
            }
        }
Exemple #5
0
 /// <summary>
 /// To create a new IM IVR.
 /// </summary>
 /// <param name="customerSession">Customer session.</param>
 /// <param name="imCall">Im call.</param>
 /// <param name="menu">Menu to use.</param>
 /// <param name="conversationContextChannel">Conversation context channel.</param>
 /// <param name="logger">Logger.</param>
 public InstantMessagingIVR(CustomerSession customerSession,
                            InstantMessagingCall imCall,
                            ConversationContextChannel conversationContextChannel,
                            Menu menu,
                            ILogger logger)
 {
     this.customerSession = customerSession;
     this.logger          = logger;
     this.imCall          = imCall;
     this.RegisterIMcallEventHandlers(imCall);
     this.menu = menu;
     if (conversationContextChannel != null)
     {
         this.channel = conversationContextChannel;
         this.RegisterContextChannelHandlers(this.channel);
     }
 }
Exemple #6
0
        // Callback for BeginContextEstablish on the context channel.
        void BeginContextEstablishCB(IAsyncResult res)
        {
            ConversationContextChannel channel = res as ConversationContextChannel;

            try
            {
                if (channel.State == ConversationContextChannelState.Establishing)
                {
                    NonBlockingConsole.WriteLine("Context channel is in the Establishing state");
                    channel.EndEstablish(res);
                }
            }
            catch (Exception e)
            {
                NonBlockingConsole.WriteLine("Error: Context channel establish failed with exception: " + e.ToString());
            }
        }
Exemple #7
0
 private void InitConversationContext()
 {
     if (_localConvContextChannel != null && _localEndpoint != null)
     {
         _localConvContextChannel = new ConversationContextChannel(_conversation, _remoteEndpoint);
         ConversationContextChannelEstablishOptions options = new ConversationContextChannelEstablishOptions();
         options.ApplicationName      = _appName;
         options.RemoteConversationId = _conversation.Id;
         options.ContextualData       = GetTranscriptMessageContextualData();
         _localConvContextChannel.BeginEstablish(_appId, options, BeginContextEstablishCB, _localConvContextChannel);
     }
     if (_convContextChannel != null && _remoteEndpoint != null)
     {
         _convContextChannel = new ConversationContextChannel(_conversation, _remoteEndpoint);
         ConversationContextChannelEstablishOptions options = new ConversationContextChannelEstablishOptions();
         options.ApplicationName      = _appName;
         options.RemoteConversationId = _conversation.Id;
         options.ContextualData       = GetTranscriptMessageContextualData();
         _convContextChannel.BeginEstablish(_appId, options, BeginContextEstablishCB, _convContextChannel);
     }
 }
Exemple #8
0
 public AgentContextChannel(Conversation conversation, ParticipantEndpoint remoteEndpoint)
 {
     m_innerChannel = new ConversationContextChannel(conversation, remoteEndpoint);
 }
 private void InitConversationContext()
 {
     if (_localConvContextChannel != null && _localEndpoint != null)
     {
         _localConvContextChannel = new ConversationContextChannel(_conversation, _remoteEndpoint);
         ConversationContextChannelEstablishOptions options = new ConversationContextChannelEstablishOptions();
         options.ApplicationName = _appName;
         options.RemoteConversationId = _conversation.Id;
         options.ContextualData = GetTranscriptMessageContextualData();
         _localConvContextChannel.BeginEstablish(_appId, options, BeginContextEstablishCB, _localConvContextChannel);
     }
     if (_convContextChannel != null && _remoteEndpoint != null)
     {
         _convContextChannel = new ConversationContextChannel(_conversation, _remoteEndpoint);
         ConversationContextChannelEstablishOptions options = new ConversationContextChannelEstablishOptions();
         options.ApplicationName = _appName;
         options.RemoteConversationId = _conversation.Id;
         options.ContextualData = GetTranscriptMessageContextualData();
         _convContextChannel.BeginEstablish(_appId, options, BeginContextEstablishCB, _convContextChannel);
     }
 }
Exemple #10
0
 public static Task EstablishAsync(this ConversationContextChannel channel,
                                   Guid applicationId, ConversationContextChannelEstablishOptions options)
 {
     return(Task.Factory.FromAsync(channel.BeginEstablish,
                                   channel.EndEstablish, applicationId, options, null));
 }
Exemple #11
0
 public static Task TerminateAsync(this ConversationContextChannel channel)
 {
     return(Task.Factory.FromAsync(channel.BeginTerminate,
                                   channel.EndTerminate, null));
 }
Exemple #12
0
 public static Task SendDataAsync(this ConversationContextChannel channel,
                                  ContentType contentType, byte[] contentBody)
 {
     return(Task.Factory.FromAsync(channel.BeginSendData,
                                   channel.EndSendData, contentType, contentBody, null));
 }
Exemple #13
0
 /// <summary>
 /// Unregisters conversation context channel handlers.
 /// </summary>
 /// <param name="channel">Channel.</param>
 private void UnregisterContextChannelHandlers(ConversationContextChannel channel)
 {
     channel.StateChanged -= this.ChannelStateChanged;
 }
Exemple #14
0
        /// <summary>
        /// Handle incoming IM call from the customer.
        /// </summary>
        /// <param name="imCall">IM call.</param>
        public void HandleIncomingInstantMessagingCall(InstantMessagingCall imCall)
        {
            lock (syncRoot)
            {
                if (this.conversation == null)
                {
                    this.conversation = imCall.Conversation;
                    this.RegisterConversationEventHandlers(this.conversation);
                }

                if (this.conversationContextChannel == null && !String.IsNullOrEmpty(this.application.CweGuid))
                {
                    this.conversationContextChannel = new ConversationContextChannel(this.conversation, imCall.RemoteEndpoint);
                    this.RegisterContextChannelHandlers(this.conversationContextChannel);
                }


                this.imIvr = new InstantMessagingIVR(this, imCall, this.conversationContextChannel, this.menu, this.logger);

                this.imIvr.isUserEndpointFirstMessage = true;

                try
                {
                    imCall.BeginAccept((asyncResult) =>
                    {
                        try
                        {
                            imCall.EndAccept(asyncResult);
                            if (this.conversationContextChannel != null && this.conversationContextChannel.State == ConversationContextChannelState.Idle)
                            {
                                ConversationContextChannelEstablishOptions channelOptions = new ConversationContextChannelEstablishOptions();
                                channelOptions.ApplicationName = this.application.Name;
                                channelOptions.ContextualData  = "Context channel is open.";
                                channelOptions.Toast           = "Please check the accompaining CWE window for Graphical Experience";
                                Guid appGuid = new Guid(this.application.CweGuid);

                                try
                                {
                                    this.conversationContextChannel.BeginEstablish(appGuid,
                                                                                   channelOptions,
                                                                                   (contextChannelAsyncResult) =>
                                    {
                                        try
                                        {
                                            this.conversationContextChannel.EndEstablish(contextChannelAsyncResult);
                                        }
                                        catch (RealTimeException rte)
                                        {
                                            Console.WriteLine("Error establishing conversation context channel {0}", rte);
                                            this.logger.Log("Error establishing conversation context channel {0}", rte);
                                        }
                                    },
                                                                                   null);
                                }
                                catch (InvalidOperationException ioe)
                                {
                                    Console.WriteLine("Error establishing conversation context channel {0}", ioe);
                                    this.logger.Log("Error establishing conversation context channel {0}", ioe);
                                }
                            }
                        }
                        catch (RealTimeException rte)
                        {
                            Console.WriteLine("Error accepting incoming IM call {0}", rte);
                            this.logger.Log("Error accepting incoming IM call {0}", rte);
                        }
                    },
                                       null);
                }
                catch (InvalidOperationException ioe)
                {
                    Console.WriteLine("Error accepting incoming IM call {0}", ioe);
                    this.logger.Log("Error accepting incoming IM call {0}", ioe);
                }
            }
        }
Exemple #15
0
 /// <summary>
 /// Unregisters conversation context channel handlers.
 /// </summary>
 /// <param name="channel">Channel.</param>
 private void UnregisterContextChannelHandlers(ConversationContextChannel channel)
 {
     channel.DataReceived -= this.ChannelDataReceived;
 }
Exemple #16
0
 public WhisperRequest(requestType request,
                       ConversationContextChannel channel)
     : base(request, ContextChannelRequestType.Whisper, channel)
 {
     m_uri = new Uri(request.whisper.uri);
 }
Exemple #17
0
 public EscalateRequest(requestType request,
                        ConversationContextChannel channel)
     : base(request, ContextChannelRequestType.Escalate, channel)
 {
     m_skills = new List <agentSkillType>(request.escalate.agentSkills);
 }
Exemple #18
0
        public override async Task<AcdActionResult> Execute(LocalEndpoint localEndpoint, AudioVideoCall call, CancellationToken cancellationToken)
        {
            if (Endpoint == null)
                return AcdActionResult.Continue;

            // extract information from incoming caller
            var callParticipant = call.RemoteEndpoint.Participant;
            var callAddress = new RealTimeAddress(callParticipant.Uri, localEndpoint.DefaultDomain, localEndpoint.PhoneContext);
            var callSipUri = new SipUriParser(callAddress.Uri);
            callSipUri.RemoveParameter(new SipUriParameter("user", "phone"));
            var callUri = callSipUri.ToString();
            var callPhoneUri = callParticipant.OtherPhoneUri;
            var callName = callParticipant.DisplayName;

            // impersonate incoming caller to agent
            var remoteConversation = new Conversation(localEndpoint);
            remoteConversation.Impersonate(callUri, callPhoneUri, callName);

            // establish call to endpoint
            var remoteCall = new AudioVideoCall(remoteConversation);
            var remoteOpts = new CallEstablishOptions();
            remoteOpts.Transferor = localEndpoint.OwnerUri;
            remoteOpts.Headers.Add(new SignalingHeader("Ms-Target-Class", "secondary"));

            // initiate call with duration
            var destCallT = remoteCall.EstablishAsync(Endpoint.Uri, remoteOpts, cancellationToken);

            try
            {
                // wait for agent call to complete
                await destCallT;
            }
            catch (OperationCanceledException)
            {
                // ignore
            }
            catch (RealTimeException)
            {
                // ignore
            }

            // ensure two accepted transfers cannot both complete
            using (var lck = await call.GetContext<AsyncLock>().LockAsync())
                if (call.State == CallState.Established)
                    if (remoteCall.State == CallState.Established)
                    {
                        var participant = remoteConversation.RemoteParticipants.FirstOrDefault();
                        if (participant != null)
                        {
                            var endpoint = participant.GetEndpoints().FirstOrDefault(i => i.EndpointType == EndpointType.User);
                            if (endpoint != null)
                            {
                                var ctx = new ConversationContextChannel(remoteConversation, endpoint);

                                // establish conversation context with application
                                await ctx.EstablishAsync(
                                    new Guid("FA44026B-CC48-42DA-AAA8-B849BCB43A21"), 
                                    new ConversationContextChannelEstablishOptions());

                                // send context data
                                await ctx.SendDataAsync(
                                    new ContentType("text/plain"), 
                                    Encoding.UTF8.GetBytes("Id=123"));
                            }
                        }

                        return await TransferAsync(call, remoteCall);
                    }

            // terminate outbound call if still available
            if (remoteCall.State != CallState.Terminating &&
                remoteCall.State != CallState.Terminated)
                await remoteCall.TerminateAsync();

            // we could not complete the transfer attempt
            return AcdActionResult.Continue;
        }