From 71b63a7f122eca12e29ac22dc083db2ce82c6fe8 Mon Sep 17 00:00:00 2001 From: Gary Pretty Date: Thu, 9 Jun 2022 09:50:11 +0100 Subject: [PATCH] Multiple fixes (#489) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Swallow handoff events and suppport datetime (#404) * Swallow handoff events and suppport datetime Ensure handoff events handled by the handoff middleware are swallowed and not passed to the user. Update ServiceNow controller / middleware to handle datetimepicker. Update readme. * Fix link / multi link support and add card support * Update TokenExchangeSkillHandler tags and package info (#397) Fixes: https://github.com/BotBuilderCommunity/botbuilder-community-dotnet/issues/396 * Added TextRecognizer middlware compoent (#402) * Added TextRecognizer middlware compoent * Added readme file for TextRecognizer middleware * Updated readme.md file * Replace with Bot_Builder_Version tag * add it to the turn state and remove from conversation state * Updated read.md file * Add Sentiment Analysis Middleware Component (#400) * chore: update the SentimentAnalyzer reference for Sentiment Analysis Middleware * chore: add the Sentiment Analysis Middleware component * chore: modified the description. * Update README.md Add all the relevant details * chore: add solution file and fixed the null check * chore: add it to the turn state and remove from conversation state after discussing with SDK team Co-authored-by: Gary Pretty * ServiceNow Component Updates (#407) * Swallow handoff events and suppport datetime Ensure handoff events handled by the handoff middleware are swallowed and not passed to the user. Update ServiceNow controller / middleware to handle datetimepicker. Update readme. * Fix link / multi link support and add card support * Updates for images / carousels * Add Google Business Messaging Adapter Component (#408) * Add Google Business Messaging Component * Update project file and component registration * Add package icon * Include schemas in project * Add incoming message validation and partnerKey property * Change to UTF8 encoding in the body validation when requesting authorization (#439) * StreamReader overload to specify UTF8 encoding type StreamReader overload to UTF8 encoding type in order to have more compatibility with the character sets of other languages ​​apart from English. since this can generate incompatibility in certain cases such as in #435 * Change from ASCII to UTF8 encoding in _requestBodyByte Change from ASCII to UTF8 encoding type in the body request to have more compatibility with the character sets of other languages ​​apart from English. since this can generate incompatibility in certain cases such as in #435 * Include gifs in cards library readme (#431) Co-authored-by: Kyle Delaney * Update cards library sample dependencies (#430) Co-authored-by: Kyle * Added null conditional operators for default case and outputText Case to handle Null reference exception (#425) * Resolved the issue by adding text inside the hero card, changed item.header to display title for the single link response type. (#426) * Modifications made in the else part of picker case and boolean case to render the text within the hero card instead of separate message. (#424) * Limiting the number of buttons to 50 and cards to 10 that can be rendered in a Hero card carousel. (#423) * A new response type called OutPutHTML is released in the latest build. With this release, the rich text is not shown and line breaks are missing, displays as a plain text. (#428) * UI change to Incident card Keys/Titles like Short description to be bold in the card response type. (#422) * Added Multi select choice input (#420) * Added Multi select choice input * Create README.md * Document has updated * URL is not constructed properly (#427) * Checking for the takeControl flag along with the responseMessage.completed flag to hand over back the user to MS Bot (#421) * Removed unnecessary param in the payload (#429) * Removed unnecessary param in the payload * Revert "Removed unnecessary param in the payload" This reverts commit 4003a9f67ae73e9970fa0eb9dffe4d4254b33019. * Removed unnecessary param in the payload * Fix for Ticket Details are truncating and not wrapping (#452) Co-authored-by: Palanikumar Ravichandran * Update token exchange skill handler readme (#440) * Update readme.md * Update readme.md * Update readme.md Co-authored-by: Gary Pretty * Expire Conversation Trigger for Bot composer (#456) * Added expire conversation trigger * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md Co-authored-by: Gary Pretty * Bump RestSharp in /libraries/Bot.Builder.Community.Adapters.Zoom (#445) Bumps [RestSharp](https://github.com/restsharp/RestSharp) from 106.10.2-alpha.0.8 to 106.12.0. - [Release notes](https://github.com/restsharp/RestSharp/releases) - [Changelog](https://github.com/restsharp/RestSharp/blob/dev/releasenotes.md) - [Commits](https://github.com/restsharp/RestSharp/commits/106.12) --- updated-dependencies: - dependency-name: RestSharp dependency-type: direct:production ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Gary Pretty * Added custom Bot composer dialog Inputs (#457) * Added custom inputs * Added custom dialog inputs * Added custom dialog inputs Co-authored-by: Gary Pretty * Move Facebook, Slack, Twilio, Webex adapters (#461) * Copy Facebook Adapter * Delete schema files * Rename project file. * -Change namespace -Remove unused usings -Remove Microsoft copyright notice * Add README, project file, update solution * Add Slack, Twilio, Webex initial copy from MS repo * Slack - update namespace, remove MS copyright notice, remove ununsed usings * Twilio - update namespaces, remove MS copyright * Webex - update namespace, remove copyright * Remove schemas, icons * Add fully qualified name to Schema * Add Facebook, Slack, Twilio, Webex tests from MS repo * Update adapters tests * Update READMEs * Remove old project file * Remove old project files. * MessageBird adapter for BotComposer (#460) * MessageBird adapter for BotComposer * MessageBird adapter for BotComposer * MessageBird adapter for BotComposer * MessageBird adapter for BotComposer * Update BotBuilderCommunity.MessageBirdAdapter.schema Co-authored-by: Gary Pretty * Google adapter fix for Access Token (#463) Co-authored-by: Gary Pretty * MessageBird API New Request Verification Method and Breaking Changes (#467) * #466 * switch statement added, if/else blokcs are removed. * added caption support for MediaContent's like image, video, audio, file * fixed some unnecessary indentations * Changed sample , image caption and added Sample project to the solution file * fix content type for samples * added sample code to readme file * more fixing readme file * updating composer component to reflect the breaking changes of the adapter, NuGet tags and description * reverting a tag for NuGet * Move Samples for Facebook, Slack, Twilio, Webex adapters (#472) * Copy Facebook Adapter * Delete schema files * Rename project file. * -Change namespace -Remove unused usings -Remove Microsoft copyright notice * Add README, project file, update solution * Add Slack, Twilio, Webex initial copy from MS repo * Slack - update namespace, remove MS copyright notice, remove ununsed usings * Twilio - update namespaces, remove MS copyright * Webex - update namespace, remove copyright * Remove schemas, icons * Add fully qualified name to Schema * Add Facebook, Slack, Twilio, Webex tests from MS repo * Update adapters tests * Update READMEs * Remove old project file * Remove old project files. * Add Facebook, Twilio, Slack, Webex adapter samples. * Update namespaces, remove copyright notice, update adapter package references, update READMEs. * Update namespaces. * Update READMEs. * Update test projects target framework to netcoreapp3.1. * Bug fix for mapping of item in reaction_event (#478) * Bug fix for mapping of item in reaction_event * restoring message body * minor fixe * fixed spacing * fixed spacing Co-authored-by: Anshul Sharma * Changing encoding from ASCII to UTF8 to support extended charset (#480) * change split character (#477) * Webex Adapter: Adding support for Markdown and set default text format to Markdown instead of plain text (#482) * adding reference to Bot.Builder.Community.Adapters.Share * handling format and passing MessageTextType to CreateMessageAsync and CreateMessageWithAttachmentsAsync * Adding support for markdown and additional plain text * Setting default text format to markdown * Add activity to google event for GoogleBusinessMessagingRequestMapper (#483) * Add activity to google event mapping * update display name Co-authored-by: Eric Dahlvang Co-authored-by: Vinoth Rajendran Co-authored-by: Arafat Tehsin Co-authored-by: Ricardo Zamudio <46466785+JustZeus@users.noreply.github.com> Co-authored-by: Kyle Delaney Co-authored-by: Kyle Delaney Co-authored-by: Amit-singh96 <85606479+Amit-singh96@users.noreply.github.com> Co-authored-by: newlogics <30690070+newlogics@users.noreply.github.com> Co-authored-by: Palanikumar Ravichandran Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Monica Rivera <44449640+mrivera-ms@users.noreply.github.com> Co-authored-by: lauren-mills Co-authored-by: ahmetkocadogan Co-authored-by: Anshul21 Co-authored-by: Anshul Sharma Co-authored-by: Bastian Thiede <34596230+bastian-thiede@users.noreply.github.com> Co-authored-by: Zhipeng Wang --- .../ToActivityConverter.cs | 4 ++-- .../ToMessageBirdConverter.cs | 2 +- .../Model/EventType.cs | 5 ++-- ...ot.Builder.Community.Adapters.Webex.csproj | 4 ++++ .../WebexAdapter.cs | 15 +++++++++--- .../WebexClientWrapper.cs | 23 ++++++++++++++----- .../GoogleBusinessMessagingRequestMapper.cs | 12 ++++++++++ .../Model/GoogleEventType.cs | 11 +++++++++ .../Model/OutgoingEvent.cs | 17 ++++++++++++++ .../Model/OutgoingMessage.cs | 2 +- 10 files changed, 79 insertions(+), 16 deletions(-) create mode 100644 libraries/Bot.Builder.Community.Components.Adapters.GoogleBusiness.Core/Model/GoogleEventType.cs create mode 100644 libraries/Bot.Builder.Community.Components.Adapters.GoogleBusiness.Core/Model/OutgoingEvent.cs diff --git a/libraries/Bot.Builder.Community.Adapters.MessageBird/ToActivityConverter.cs b/libraries/Bot.Builder.Community.Adapters.MessageBird/ToActivityConverter.cs index fbff4ad3..bc3ce1bc 100644 --- a/libraries/Bot.Builder.Community.Adapters.MessageBird/ToActivityConverter.cs +++ b/libraries/Bot.Builder.Community.Adapters.MessageBird/ToActivityConverter.cs @@ -45,7 +45,7 @@ private Activity ConvertToActivity(MessageBirdWebhookPayload response) { Type = ActivityTypes.Event, Id = response.message.id, - ChannelId = $"{response.message.platform}-{response.message.channelId}", + ChannelId = $"{response.message.platform}#{response.message.channelId}", ChannelData = response, Recipient = new ChannelAccount { Id = response.message.to }, From = new ChannelAccount { Id = response.message.from ?? "you" }, @@ -73,7 +73,7 @@ private IActivity ConvertMessageToMessageActivity(MessageBirdWebhookPayload resp activity.Type = ActivityTypes.Message; activity.Id = response.message.id; - activity.ChannelId = $"{response.message.platform}-{response.message.channelId}"; + activity.ChannelId = $"{response.message.platform}#{response.message.channelId}"; activity.ChannelData = response; activity.Recipient = new ChannelAccount { Id = response.message.to }; activity.From = new ChannelAccount { Id = response.message.from }; diff --git a/libraries/Bot.Builder.Community.Adapters.MessageBird/ToMessageBirdConverter.cs b/libraries/Bot.Builder.Community.Adapters.MessageBird/ToMessageBirdConverter.cs index b3be2de9..057110da 100644 --- a/libraries/Bot.Builder.Community.Adapters.MessageBird/ToMessageBirdConverter.cs +++ b/libraries/Bot.Builder.Community.Adapters.MessageBird/ToMessageBirdConverter.cs @@ -150,7 +150,7 @@ private static MessageBirdSendMessagePayload CreateMessage(IMessageActivity acti conversationMessageRequest = new ConversationMessageSendRequest() { ConversationId = activity.Conversation.Id, - ChannelId = activity.ChannelId.Split('-')[1] + ChannelId = activity.ChannelId.Split('#')[1] } }; } diff --git a/libraries/Bot.Builder.Community.Adapters.Slack/Model/EventType.cs b/libraries/Bot.Builder.Community.Adapters.Slack/Model/EventType.cs index b70e4385..f422b401 100644 --- a/libraries/Bot.Builder.Community.Adapters.Slack/Model/EventType.cs +++ b/libraries/Bot.Builder.Community.Adapters.Slack/Model/EventType.cs @@ -16,11 +16,10 @@ public class EventType public string Ts { get; set; } - public JObject Item { get; } = new JObject(); + public JObject Item { get; set;} [JsonProperty(PropertyName = "event_ts")] public string EventTs { get; set; } - public string Channel { get; set; } [JsonProperty(PropertyName = "channel_id")] @@ -35,4 +34,4 @@ public class EventType [JsonExtensionData(ReadData = true, WriteData = true)] public IDictionary AdditionalProperties { get; } = new Dictionary(); } -} +} \ No newline at end of file diff --git a/libraries/Bot.Builder.Community.Adapters.Webex/Bot.Builder.Community.Adapters.Webex.csproj b/libraries/Bot.Builder.Community.Adapters.Webex/Bot.Builder.Community.Adapters.Webex.csproj index 4c211497..b1beace8 100644 --- a/libraries/Bot.Builder.Community.Adapters.Webex/Bot.Builder.Community.Adapters.Webex.csproj +++ b/libraries/Bot.Builder.Community.Adapters.Webex/Bot.Builder.Community.Adapters.Webex.csproj @@ -36,4 +36,8 @@ + + + + \ No newline at end of file diff --git a/libraries/Bot.Builder.Community.Adapters.Webex/WebexAdapter.cs b/libraries/Bot.Builder.Community.Adapters.Webex/WebexAdapter.cs index 111faee2..9f9452ab 100644 --- a/libraries/Bot.Builder.Community.Adapters.Webex/WebexAdapter.cs +++ b/libraries/Bot.Builder.Community.Adapters.Webex/WebexAdapter.cs @@ -86,6 +86,15 @@ public override async Task SendActivitiesAsync(ITurnContext string recipientId; var target = MessageTarget.PersonId; + // map text format + if (activity.TextFormat == TextFormatTypes.Xml) + { + _logger.LogTrace($"Unsupported TextFormat: '{activity.TextFormat}'. Only TextFormat of types 'Plain' or 'Markdown' are supported."); + activity.TextFormat = TextFormatTypes.Plain; + } + + var messageType = activity.TextFormat == TextFormatTypes.Plain ? MessageTextType.Text : MessageTextType.Markdown; + if (activity.Conversation?.Id != null) { recipientId = activity.Conversation.Id; @@ -110,7 +119,7 @@ public override async Task SendActivitiesAsync(ITurnContext { if (activity.Attachments[0].ContentType == "application/vnd.microsoft.card.adaptive") { - responseId = await _webexClient.CreateMessageWithAttachmentsAsync(recipientId, activity.Text, activity.Attachments, MessageTextType.Text, target, cancellationToken).ConfigureAwait(false); + responseId = await _webexClient.CreateMessageWithAttachmentsAsync(recipientId, activity.Text, activity.Attachments, messageType, target, cancellationToken).ConfigureAwait(false); } else { @@ -122,13 +131,13 @@ public override async Task SendActivitiesAsync(ITurnContext files.Add(file); } - responseId = await _webexClient.CreateMessageAsync(recipientId, activity.Text, files.Count > 0 ? files : null, MessageTextType.Text, target, cancellationToken).ConfigureAwait(false); + responseId = await _webexClient.CreateMessageAsync(recipientId, activity.Text, files.Count > 0 ? files : null, messageType, target, cancellationToken).ConfigureAwait(false); } } else { responseId = await _webexClient - .CreateMessageAsync(recipientId, activity.Text, target: target, cancellationToken: cancellationToken) + .CreateMessageAsync(recipientId, activity.Text, messageType: messageType, target: target, cancellationToken: cancellationToken) .ConfigureAwait(false); } diff --git a/libraries/Bot.Builder.Community.Adapters.Webex/WebexClientWrapper.cs b/libraries/Bot.Builder.Community.Adapters.Webex/WebexClientWrapper.cs index 162a80b5..94b54ec3 100644 --- a/libraries/Bot.Builder.Community.Adapters.Webex/WebexClientWrapper.cs +++ b/libraries/Bot.Builder.Community.Adapters.Webex/WebexClientWrapper.cs @@ -85,7 +85,7 @@ public virtual bool ValidateSignature(HttpRequest request, string jsonPayload) /// Target for the message. /// A cancellation token for the task. /// The created message id. - public virtual async Task CreateMessageAsync(string recipient, string text, IList files = null, MessageTextType messageType = MessageTextType.Text, MessageTarget target = MessageTarget.PersonId, CancellationToken cancellationToken = default) + public virtual async Task CreateMessageAsync(string recipient, string text, IList files = null, MessageTextType messageType = MessageTextType.Markdown, MessageTarget target = MessageTarget.PersonId, CancellationToken cancellationToken = default) { var webexResponse = await _api.CreateMessageAsync(recipient, text, files, target, messageType, cancellationToken: cancellationToken).ConfigureAwait(false); @@ -107,13 +107,13 @@ public virtual async Task DeleteMessageAsync(string messageId, CancellationToken /// Creates a message with attachments. /// /// PersonId, email or roomId of the message. - /// Text of the message. + /// Text or markdown of the message. /// List of attachments attached to the message. /// Type of the message. It can be Text or Markdown. /// Target for the message. /// A cancellation token for the task. /// The created message id. - public virtual async Task CreateMessageWithAttachmentsAsync(string recipient, string text, IList attachments, MessageTextType messageType = MessageTextType.Text, MessageTarget target = MessageTarget.PersonId, CancellationToken cancellationToken = default) + public virtual async Task CreateMessageWithAttachmentsAsync(string recipient, string textOrMarkdown, IList attachments, MessageTextType messageType = MessageTextType.Markdown, MessageTarget target = MessageTarget.PersonId, CancellationToken cancellationToken = default) { Message result; @@ -124,11 +124,21 @@ public virtual async Task CreateMessageWithAttachmentsAsync(string recip attachmentsContent.Add(attach.Content); } + var text = textOrMarkdown ?? string.Empty; + string markdown = null; + + if (!string.IsNullOrEmpty(textOrMarkdown) && messageType == MessageTextType.Markdown) + { + markdown = textOrMarkdown; + text = Shared.MarkdownToPlaintextRenderer.Render(textOrMarkdown); + } + var request = new WebexMessageRequest { RoomId = target == MessageTarget.SpaceId ? recipient : null, ToPersonId = target == MessageTarget.SpaceId ? null : recipient, - Text = text ?? string.Empty, + Text = text, + Markdown = markdown, Attachments = attachmentsContent.Count > 0 ? attachmentsContent : null, }; @@ -136,11 +146,12 @@ public virtual async Task CreateMessageWithAttachmentsAsync(string recip http.PreAuthenticate = true; http.Headers.Add("Authorization", "Bearer " + Options.WebexAccessToken); http.Accept = "application/json"; - http.ContentType = "application/json"; + http.ContentType = "application/json" + + "; charset=utf-8"; http.Method = "POST"; var parsedContent = JsonConvert.SerializeObject(request); - var encoding = new ASCIIEncoding(); + var encoding = new UTF8Encoding(); var bytes = encoding.GetBytes(parsedContent); var newStream = await http.GetRequestStreamAsync().ConfigureAwait(false); diff --git a/libraries/Bot.Builder.Community.Components.Adapters.GoogleBusiness.Core/GoogleBusinessMessagingRequestMapper.cs b/libraries/Bot.Builder.Community.Components.Adapters.GoogleBusiness.Core/GoogleBusinessMessagingRequestMapper.cs index 31a562e2..db93618e 100644 --- a/libraries/Bot.Builder.Community.Components.Adapters.GoogleBusiness.Core/GoogleBusinessMessagingRequestMapper.cs +++ b/libraries/Bot.Builder.Community.Components.Adapters.GoogleBusiness.Core/GoogleBusinessMessagingRequestMapper.cs @@ -33,6 +33,18 @@ public Activity RequestToActivity(GoogleBusinessRequest request) return RequestToEventActivity(request); } + public OutgoingEvent ActivityToEvent(Activity activity) + { + var googleEvent = new OutgoingEvent(); + + if (activity is ITypingActivity) + googleEvent.EventType = GoogleEventType.TYPING_STARTED; + else + googleEvent.EventType = GoogleEventType.EVENT_TYPE_UNSPECIFIED; + + return googleEvent; + } + public OutgoingMessage ActivityToMessage(Activity activity) { var messageId = Guid.NewGuid().ToString(); diff --git a/libraries/Bot.Builder.Community.Components.Adapters.GoogleBusiness.Core/Model/GoogleEventType.cs b/libraries/Bot.Builder.Community.Components.Adapters.GoogleBusiness.Core/Model/GoogleEventType.cs new file mode 100644 index 00000000..5df0c6c6 --- /dev/null +++ b/libraries/Bot.Builder.Community.Components.Adapters.GoogleBusiness.Core/Model/GoogleEventType.cs @@ -0,0 +1,11 @@ +namespace Bot.Builder.Community.Components.Adapters.GoogleBusiness.Core.Model +{ + public enum GoogleEventType + { + EVENT_TYPE_UNSPECIFIED, + TYPING_STARTED, + TYPING_STOPPED, + REPRESENTATIVE_JOINED, + REPRESENTATIVE_LEFT + } +} diff --git a/libraries/Bot.Builder.Community.Components.Adapters.GoogleBusiness.Core/Model/OutgoingEvent.cs b/libraries/Bot.Builder.Community.Components.Adapters.GoogleBusiness.Core/Model/OutgoingEvent.cs new file mode 100644 index 00000000..163b20b2 --- /dev/null +++ b/libraries/Bot.Builder.Community.Components.Adapters.GoogleBusiness.Core/Model/OutgoingEvent.cs @@ -0,0 +1,17 @@ +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; + +namespace Bot.Builder.Community.Components.Adapters.GoogleBusiness.Core.Model +{ + public class OutgoingEvent + { + [JsonConverter(typeof(StringEnumConverter))] + public GoogleEventType EventType { get; set; } + + public Representative Representative { get; set; } = new Representative() + { + DisplayName = "Bot", + RepresentativeType = "BOT" + }; + } +} diff --git a/libraries/Bot.Builder.Community.Components.Adapters.GoogleBusiness.Core/Model/OutgoingMessage.cs b/libraries/Bot.Builder.Community.Components.Adapters.GoogleBusiness.Core/Model/OutgoingMessage.cs index 80cc94f3..a860f55e 100644 --- a/libraries/Bot.Builder.Community.Components.Adapters.GoogleBusiness.Core/Model/OutgoingMessage.cs +++ b/libraries/Bot.Builder.Community.Components.Adapters.GoogleBusiness.Core/Model/OutgoingMessage.cs @@ -15,7 +15,7 @@ public class OutgoingMessage public Representative Representative { get; set; } = new Representative() { - DisplayName = "Contoso", + DisplayName = "Bot", RepresentativeType = "BOT" };