public void TestDeleteResponse() { var twilioRestClient = Substitute.For <ITwilioRestClient>(); twilioRestClient.AccountSid.Returns("ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); twilioRestClient.Request(Arg.Any <Request>()) .Returns(new Response( System.Net.HttpStatusCode.NoContent, "null" )); var response = ConversationResource.Delete("CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", client: twilioRestClient); Assert.NotNull(response); }
public void TestFetchResponse() { var twilioRestClient = Substitute.For <ITwilioRestClient>(); twilioRestClient.AccountSid.Returns("ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); twilioRestClient.Request(Arg.Any <Request>()) .Returns(new Response( System.Net.HttpStatusCode.OK, "{\"sid\": \"CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"account_sid\": \"ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"chat_service_sid\": \"ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"messaging_service_sid\": \"MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"friendly_name\": \"My First Conversation\",\"attributes\": \"{ \\\"topic\\\": \\\"feedback\\\" }\",\"date_created\": \"2015-12-16T22:18:37Z\",\"date_updated\": \"2015-12-16T22:18:38Z\",\"state\": \"active\",\"timers\": {\"date_inactive\": \"2015-12-16T22:19:38Z\",\"date_closed\": \"2015-12-16T22:28:38Z\"},\"url\": \"https://conversations.twilio.com/v1/Conversations/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"links\": {\"participants\": \"https://conversations.twilio.com/v1/Conversations/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Participants\",\"messages\": \"https://conversations.twilio.com/v1/Conversations/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages\",\"webhooks\": \"https://conversations.twilio.com/v1/Conversations/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Webhooks\"}}" )); var response = ConversationResource.Fetch("CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", client: twilioRestClient); Assert.NotNull(response); }
public void TestCreateNoTimersNoAttributesResponse() { var twilioRestClient = Substitute.For <ITwilioRestClient>(); twilioRestClient.AccountSid.Returns("ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); twilioRestClient.Request(Arg.Any <Request>()) .Returns(new Response( System.Net.HttpStatusCode.Created, "{\"sid\": \"CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"account_sid\": \"ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"chat_service_sid\": \"ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"messaging_service_sid\": \"MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"friendly_name\": \"friendly_name\",\"unique_name\": null,\"attributes\": \"{}\",\"date_created\": \"2020-07-01T22:18:37Z\",\"date_updated\": \"2020-07-01T22:18:37Z\",\"state\": \"active\",\"timers\": {},\"url\": \"https://conversations.twilio.com/v1/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Conversations/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"links\": {\"participants\": \"https://conversations.twilio.com/v1/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Conversations/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Participants\",\"messages\": \"https://conversations.twilio.com/v1/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Conversations/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages\",\"webhooks\": \"https://conversations.twilio.com/v1/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Conversations/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Webhooks\"}}" )); var response = ConversationResource.Create("ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", xTwilioWebhookEnabled: Serialize(ConversationResource.WebhookEnabledTypeEnum.True), client: twilioRestClient); Assert.NotNull(response); }
public void TestReadFullResponse() { var twilioRestClient = Substitute.For <ITwilioRestClient>(); twilioRestClient.AccountSid.Returns("ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); twilioRestClient.Request(Arg.Any <Request>()) .Returns(new Response( System.Net.HttpStatusCode.OK, "{\"conversations\": [{\"sid\": \"CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"account_sid\": \"ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"chat_service_sid\": \"ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"messaging_service_sid\": \"MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"friendly_name\": \"Home Repair Visit\",\"unique_name\": null,\"attributes\": \"{ \\\"topic\\\": \\\"feedback\\\" }\",\"date_created\": \"2015-12-16T22:18:37Z\",\"date_updated\": \"2015-12-16T22:18:38Z\",\"state\": \"active\",\"timers\": {\"date_inactive\": \"2015-12-16T22:19:38Z\",\"date_closed\": \"2015-12-16T22:28:38Z\"},\"url\": \"https://conversations.twilio.com/v1/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Conversations/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"links\": {\"participants\": \"https://conversations.twilio.com/v1/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Conversations/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Participants\",\"messages\": \"https://conversations.twilio.com/v1/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Conversations/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages\",\"webhooks\": \"https://conversations.twilio.com/v1/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Conversations/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Webhooks\"}}],\"meta\": {\"page\": 0,\"page_size\": 50,\"first_page_url\": \"https://conversations.twilio.com/v1/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Conversations?PageSize=50&Page=0\",\"previous_page_url\": null,\"url\": \"https://conversations.twilio.com/v1/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Conversations?PageSize=50&Page=0\",\"next_page_url\": null,\"key\": \"conversations\"}}" )); var response = ConversationResource.Read("ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", client: twilioRestClient); Assert.NotNull(response); }
public void TestCreateResponse() { var twilioRestClient = Substitute.For <ITwilioRestClient>(); twilioRestClient.AccountSid.Returns("ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); twilioRestClient.Request(Arg.Any <Request>()) .Returns(new Response( System.Net.HttpStatusCode.Created, "{\"sid\": \"CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"account_sid\": \"ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"chat_service_sid\": \"ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"messaging_service_sid\": \"MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"friendly_name\": \"friendly_name\",\"date_created\": \"2015-12-16T22:18:37Z\",\"date_updated\": \"2015-12-16T22:18:38Z\",\"url\": \"https://conversations.twilio.com/v1/Conversations/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"links\": {\"participants\": \"https://conversations.twilio.com/v1/Conversations/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Participants\",\"messages\": \"https://conversations.twilio.com/v1/Conversations/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages\",\"webhooks\": \"https://conversations.twilio.com/v1/Conversations/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Webhooks\"}}" )); var response = ConversationResource.Create(client: twilioRestClient); Assert.NotNull(response); }
private async Task SendToTeamsChannelFromWebChat(ITurnContext <IMessageActivity> turnContext, CancellationToken cancellationToken, string message, Attachment attachment) { try { var conversationId = turnContext.Activity.Conversation.Id; ConversationResource teamsChatReferenceUsingWebConversationId = null; var conversationResourceTeamsChatReference = (await DocumentDBRepository.GetItemsAsync <ConversationResource>(c => c.WebConversationId == conversationId && c.ConversationReference != null)).FirstOrDefault(); var conversationResourceWebChatReference = (await DocumentDBRepository.GetItemsAsync <ConversationResource>(c => c.TeamsConversationId == conversationId && c.ConversationReference != null)).FirstOrDefault(); if (conversationResourceWebChatReference != null) { teamsChatReferenceUsingWebConversationId = (await DocumentDBRepository.GetItemsAsync <ConversationResource>(c => c.WebConversationId == conversationResourceWebChatReference.ConversationReference.Conversation.Id && c.ConversationReference != null)).FirstOrDefault(); } var customerInfo = await this.GetCustomerInformation(conversationId); if (customerInfo != null && (conversationResourceTeamsChatReference != null || teamsChatReferenceUsingWebConversationId != null)) { var conversationReferece = conversationResourceTeamsChatReference ?? teamsChatReferenceUsingWebConversationId; try { await((BotFrameworkAdapter)turnContext.Adapter).ContinueConversationAsync( this.configuration[Constants.MicrosoftAppIdConfigurationSettingsKey], conversationReferece.ConversationReference, async(t2, c2) => { await t2.SendActivityAsync(this.CreateMessageActivityForTeamsChannel(customerInfo, message, attachment)); }, cancellationToken); } catch (Exception e) { this.logger.LogError(e.Message + " " + e.StackTrace); } } else { await turnContext.SendActivityAsync(Constants.HelpMessageText); } } catch (Exception ex) { this.logger.LogError(ex.Message + " " + ex.StackTrace); } }
public void TestSetup() { var baseUri = new Uri("https://example.com/"); var resourceUri = new Uri("https://example.com/invitation/1"); var restfulClient = new MockRestfulClient(); var parent = new object(); Logger.RegisterLogger(new ConsoleLogger()); var applicationsResource = new ApplicationsResource(resourceUri.ToString()); m_applicationResource = new ApplicationResource(resourceUri.ToString()); var communicationResource = new CommunicationResource(resourceUri.ToString()); var conversationResource = new ConversationResource(resourceUri.ToString()); var invitationResource = new InvitationResource(resourceUri.ToString()) { Application = m_applicationResource }; var applications = new Applications(restfulClient, applicationsResource, baseUri, resourceUri, parent); var application = new Application(restfulClient, m_applicationResource, baseUri, resourceUri, applications); var communication = new Communication(restfulClient, communicationResource, baseUri, resourceUri, application); m_conversation = new Conversation(restfulClient, conversationResource, baseUri, resourceUri, communication); var mockInvitation = new Mock <Invitation <InvitationResource, TestCapabilities> >(restfulClient, invitationResource, baseUri, resourceUri, communication); mockInvitation.CallBase = true; m_invitation = mockInvitation.Object; // Resource deserealization understands only those resources which are registered. This means we cannot use mock // implementation of InvitationResource to raise any event. Raise an event for MessagingCall instead. EventsEntity eventsEntity = TestHelper.GetEventsEntityForEventsInFile("Event_MessagingInvitationCompleted.json"); m_eventContext = new EventContext() { BaseUri = baseUri, EventFullHref = resourceUri, EventEntity = eventsEntity.Senders[0].Events[0] }; }
public void TestUpdateRequest() { var twilioRestClient = Substitute.For <ITwilioRestClient>(); var request = new Request( HttpMethod.Post, Twilio.Rest.Domain.Conversations, "/v1/Conversations/CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "" ); twilioRestClient.Request(request).Throws(new ApiException("Server Error, no content")); try { ConversationResource.Update("CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 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.Conversations, "/v1/Services/ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Conversations/CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "" ); request.AddHeaderParam("X-Twilio-Webhook-Enabled", Serialize(ConversationResource.WebhookEnabledTypeEnum.True)); twilioRestClient.Request(request).Throws(new ApiException("Server Error, no content")); try { ConversationResource.Update("ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", xTwilioWebhookEnabled: Serialize(ConversationResource.WebhookEnabledTypeEnum.True), client: twilioRestClient); Assert.Fail("Expected TwilioException to be thrown for 500"); } catch (ApiException) {} twilioRestClient.Received().Request(request); }
/// <summary> /// ProcessAndDispatchEventsToChild implementation /// </summary> /// <param name="eventcontext"></param> /// <returns></returns> internal override bool ProcessAndDispatchEventsToChild(EventContext eventcontext) { //There is no child for events with sender = communication Logger.Instance.Information(string.Format("[Communication] get incoming communication event, sender: {0}, senderHref: {1}, EventResourceName: {2} EventFullHref: {3}, EventType: {4} ,LoggingContext: {5}", eventcontext.SenderResourceName, eventcontext.SenderHref, eventcontext.EventResourceName, eventcontext.EventFullHref, eventcontext.EventEntity.Relationship.ToString(), eventcontext.LoggingContext == null ? string.Empty : eventcontext.LoggingContext.ToString())); if (string.Equals(eventcontext.EventEntity.Link.Token, TokenMapper.GetTokenName(typeof(ConversationResource)))) { string conversationNormalizedUri = UriHelper.NormalizeUriWithNoQueryParameters(eventcontext.EventEntity.Link.Href, eventcontext.BaseUri); Conversation currentConversation = m_conversations.GetOrAdd(conversationNormalizedUri, (a) => { Logger.Instance.Information(string.Format("[Communication] Add conversation {0} LoggingContext: {1}", conversationNormalizedUri, eventcontext.LoggingContext == null ? string.Empty : eventcontext.LoggingContext.ToString())); ConversationResource localResource = this.ConvertToPlatformServiceResource <ConversationResource>(eventcontext); //For every conversation resource, we want to make sure it is using latest rest ful client return(new Conversation(this.RestfulClient, localResource, eventcontext.BaseUri, eventcontext.EventFullHref, this)); } ); //Remove from cache if it is a delete operation if (eventcontext.EventEntity.Relationship == EventOperation.Deleted) { Conversation removedConversation = null; Logger.Instance.Information(string.Format("[Communication] Remove conversation {0} LoggingContext: {1}", conversationNormalizedUri, eventcontext.LoggingContext == null ? string.Empty : eventcontext.LoggingContext.ToString())); m_conversations.TryRemove(conversationNormalizedUri, out removedConversation); } currentConversation.HandleResourceEvent(eventcontext); return(true); } else if (string.Equals(eventcontext.EventEntity.Link.Token, TokenMapper.GetTokenName(typeof(MessagingInvitationResource)))) { this.HandleInvitationEvent <MessagingInvitationResource>( eventcontext, (localResource) => new MessagingInvitation(this.RestfulClient, localResource, eventcontext.BaseUri, eventcontext.EventFullHref, this) ); return(true); } else if (string.Equals(eventcontext.EventEntity.Link.Token, TokenMapper.GetTokenName(typeof(AudioVideoInvitationResource)))) { this.HandleInvitationEvent <AudioVideoInvitationResource>( eventcontext, (localResource) => new AudioVideoInvitation(this.RestfulClient, localResource, eventcontext.BaseUri, eventcontext.EventFullHref, this) ); return(true); } else if (string.Equals(eventcontext.EventEntity.Link.Token, TokenMapper.GetTokenName(typeof(OnlineMeetingInvitationResource)))) { this.HandleInvitationEvent <OnlineMeetingInvitationResource>( eventcontext, (localResource) => new OnlineMeetingInvitation(this.RestfulClient, localResource, eventcontext.BaseUri, eventcontext.EventFullHref, this) ); return(true); } else if (string.Equals(eventcontext.EventEntity.Link.Token, TokenMapper.GetTokenName(typeof(ParticipantInvitationResource)))) { this.HandleInvitationEvent <ParticipantInvitationResource>( eventcontext, (localResource) => new ParticipantInvitation(this.RestfulClient, localResource, eventcontext.BaseUri, eventcontext.EventFullHref, this) ); return(true); } //TODO: Process , audioVideoInvitation, ... else { return(false); } }