Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added function to convert SigninCard to BlockKit #539

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions libraries/Bot.Builder.Community.Adapters.Slack/SlackHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ public static NewSlackMessage ActivityToSlack(Activity activity)
{
message.Blocks = HeroCardToBlockKit((HeroCard)att.Content);
}
else if (att.ContentType == SigninCard.ContentType)
{
message.Blocks = SigninCardToBlockKit((SigninCard) att.Content);
}
else
{
var newAttachment = new SlackAttachment()
Expand Down Expand Up @@ -457,5 +461,48 @@ private static JArray HeroCardToBlockKit(HeroCard heroCard)

return JArray.FromObject(blockKitContent, new JsonSerializer { NullValueHandling = NullValueHandling.Ignore });
}

private static JArray SigninCardToBlockKit(SigninCard signinCard)
{
var blockKitContent = new List<IBlock>();

if (!string.IsNullOrWhiteSpace(signinCard.Text))
{
blockKitContent.Add(new SectionBlock
{
text = new Text
{
type = TextTypes.Markdown,
text = signinCard.Text
}
});
}

if (signinCard.Buttons?.Any() == true)
{
var actionsBlock = new ActionsBlock
{
elements = signinCard.Buttons.Select(button => new ButtonElement
{
text = new Text
{
type = TextTypes.PlainText,
text = button.Title ?? button.Text ?? button.DisplayText,
emoji = true,
},

// value/url get a little tricky if the button is an OpenUrl since CardAction.Value is meant for the URL.
// We don't want to set value if it's an OpenUrl, because then the URL gets displayed in chat and sent to the bot.
value = (button.Type == ActionTypes.OpenUrl || button.Type == ActionTypes.Signin) ? null : button.Value.ToString() ?? button.DisplayText ?? button.Text,
url = (button.Type == ActionTypes.OpenUrl || button.Type == ActionTypes.Signin) ? button.Value.ToString() : null
}).ToArray()
};

blockKitContent.Add(new DividerBlock());
blockKitContent.Add(actionsBlock);
}

return JArray.FromObject(blockKitContent, new JsonSerializer { NullValueHandling = NullValueHandling.Ignore });
}
}
}