public void TestDeleteRequest()
        {
            var twilioRestClient = Substitute.For <ITwilioRestClient>();
            var request          = new Request(
                HttpMethod.Delete,
                Twilio.Rest.Domain.Conversations,
                "/v1/Conversations/CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Participants/MBXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
                ""
                );

            request.AddHeaderParam("X-Twilio-Webhook-Enabled", Serialize(ParticipantResource.WebhookEnabledTypeEnum.True));
            twilioRestClient.Request(request).Throws(new ApiException("Server Error, no content"));

            try
            {
                ParticipantResource.Delete("CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "MBXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", xTwilioWebhookEnabled: Serialize(ParticipantResource.WebhookEnabledTypeEnum.True), client: twilioRestClient);
                Assert.Fail("Expected TwilioException to be thrown for 500");
            }
            catch (ApiException) {}
            twilioRestClient.Received().Request(request);
        }
        public void TestCreateRequest()
        {
            var twilioRestClient = Substitute.For <ITwilioRestClient>();
            var request          = new Request(
                HttpMethod.Post,
                Twilio.Rest.Domain.Proxy,
                "/v1/Services/KSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Sessions/KCXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Participants",
                ""
                );

            request.AddPostParam("Identifier", Serialize("Identifier"));
            twilioRestClient.Request(request).Throws(new ApiException("Server Error, no content"));

            try
            {
                ParticipantResource.Create("KSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "KCXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "Identifier", client: twilioRestClient);
                Assert.Fail("Expected TwilioException to be thrown for 500");
            }
            catch (ApiException) {}
            twilioRestClient.Received().Request(request);
        }
        public void TestUpdateRequest()
        {
            var twilioRestClient = Substitute.For <ITwilioRestClient>();
            var request          = new Request(
                HttpMethod.Post,
                Twilio.Rest.Domain.Api,
                "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Conferences/CFXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Participants/CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.json",
                ""
                );

            twilioRestClient.AccountSid.Returns("ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
            twilioRestClient.Request(request).Throws(new ApiException("Server Error, no content"));

            try
            {
                ParticipantResource.Update("CFXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", client: twilioRestClient);
                Assert.Fail("Expected TwilioException to be thrown for 500");
            }
            catch (ApiException) {}
            twilioRestClient.Received().Request(request);
        }
예제 #4
0
        public void TestCreateRequest()
        {
            var twilioRestClient = Substitute.For <ITwilioRestClient>();
            var request          = new Request(
                HttpMethod.Post,
                Twilio.Rest.Domain.Api,
                "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Conferences/CFXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Participants.json",
                ""
                );

            request.AddPostParam("From", Serialize(new Twilio.Types.PhoneNumber("+15017122661")));
            request.AddPostParam("To", Serialize(new Twilio.Types.PhoneNumber("+15558675310")));
            twilioRestClient.AccountSid.Returns("ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
            twilioRestClient.Request(request).Throws(new ApiException("Server Error, no content"));

            try
            {
                ParticipantResource.Create("CFXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", new Twilio.Types.PhoneNumber("+15017122661"), new Twilio.Types.PhoneNumber("+15558675310"), client: twilioRestClient);
                Assert.Fail("Expected TwilioException to be thrown for 500");
            }
            catch (ApiException) {}
            twilioRestClient.Received().Request(request);
        }
        public ActionResult CallTransfer()
        {
            TwilioClient.Init(_accountSid, _authToken);


            string conferenceSid = Request.Params.Get("conference");
            string callSid       = Request.Params.Get("participant");

            ParticipantResource.Update(
                conferenceSid,
                callSid,
                hold: true
                );

            try
            {
                string json = @"{
               'selected_product': 'manager',
              'conference': '" + Request.Params.Get("conference") + @"',
              'customer': '" + Request.Params.Get("participant") + @"',
              'customer_taskSid': '" + Request.Params.Get("taskSid") + @"',
              'from': '" + Request.Params.Get("from") + @"',
               }";

                var task = TaskResource.Create(
                    _workspaceSid, attributes: JsonConvert.DeserializeObject(json).ToString(),
                    workflowSid: _workflowSid
                    );
            }
            catch (Exception e)
            {
                Console.Write(e.ToString());
            }

            return(View());
        }
예제 #6
0
        internal override bool ProcessAndDispatchEventsToChild(EventContext eventcontext)
        {
            ParticipantChangeEventArgs participantChangeEventArgs = null;

            //No child to dispatch any more, need to dispatch to child , process locally for message type
            if (string.Equals(eventcontext.EventEntity.Link.Token, TokenMapper.GetTokenName(typeof(ParticipantResource))))
            {
                if (eventcontext.EventEntity.In != null)
                {
                    //TODO: currently we do not handle in link
                    return(true);
                }

                string normalizedUri = UriHelper.NormalizeUri(eventcontext.EventEntity.Link.Href, this.BaseUri);
                ParticipantResource participantResource = this.ConvertToPlatformServiceResource <ParticipantResource>(eventcontext);
                switch (eventcontext.EventEntity.Relationship)
                {
                case EventOperation.Added:
                {
                    Participant tempParticipant = null;
                    if (!m_participantsCache.TryGetValue(normalizedUri, out tempParticipant))
                    {
                        tempParticipant = new Participant(this.RestfulClient, participantResource, this.BaseUri, UriHelper.CreateAbsoluteUri(this.BaseUri, eventcontext.EventEntity.Link.Href), this.Parent as Conversation);
                        m_participantsCache.TryAdd(normalizedUri, tempParticipant);
                        participantChangeEventArgs = new ParticipantChangeEventArgs();
                        participantChangeEventArgs.AddedParticipants = new List <IParticipant> {
                            tempParticipant
                        };
                    }
                    else
                    {
                        //Should get some participant added In event , ignore currently
                    }
                    break;
                }

                case EventOperation.Updated:
                {
                    Participant tempParticipant = null;
                    if (!m_participantsCache.TryGetValue(normalizedUri, out tempParticipant))
                    {
                        Logger.Instance.Warning("Get a participant updated event for a participant not in cache, any error happened ?");
                        tempParticipant = new Participant(this.RestfulClient, participantResource, this.BaseUri, UriHelper.CreateAbsoluteUri(this.BaseUri, eventcontext.EventEntity.Link.Href), this.Parent as Conversation);
                        m_participantsCache.TryAdd(normalizedUri, tempParticipant);
                    }
                    tempParticipant.HandleResourceEvent(eventcontext);
                    participantChangeEventArgs = new ParticipantChangeEventArgs();
                    participantChangeEventArgs.UpdatedParticipants = new List <IParticipant> {
                        tempParticipant
                    };
                    break;
                }

                case EventOperation.Deleted:
                {
                    Participant tempParticipant = null;
                    if (m_participantsCache.TryRemove(normalizedUri, out tempParticipant))
                    {
                        tempParticipant.HandleResourceEvent(eventcontext);
                        participantChangeEventArgs = new ParticipantChangeEventArgs();
                        participantChangeEventArgs.RemovedParticipants = new List <IParticipant> {
                            tempParticipant
                        };
                    }
                    break;
                }
                }

                if (participantChangeEventArgs != null)
                {
                    var conv = this.Parent as Conversation;
                    conv.OnParticipantChange(participantChangeEventArgs);
                }

                return(true);
            }
            else if (string.Equals(eventcontext.EventEntity.Link.Token, TokenMapper.GetTokenName(typeof(ParticipantMessagingResource))) ||
                     string.Equals(eventcontext.EventEntity.Link.Token, TokenMapper.GetTokenName(typeof(ParticipantAudioResource))) ||
                     string.Equals(eventcontext.EventEntity.Link.Token, TokenMapper.GetTokenName(typeof(ParticipantApplicationSharingResource))))
            {
                if (eventcontext.EventEntity.In != null)
                {
                    string      normalizedParticipantUri = UriHelper.NormalizeUri(eventcontext.EventEntity.In.Href, this.BaseUri);
                    Participant tempParticipant          = null;
                    if (m_participantsCache.TryGetValue(normalizedParticipantUri, out tempParticipant))
                    {
                        tempParticipant.ProcessAndDispatchEventsToChild(eventcontext);
                    }
                }

                return(true); //We do not rely on the response of tempParticipant.ProcessAndDispatchEventsToChild since we already know this is participant modality event
            }
            else
            {
                return(false);
            }
        }