2022-08-19 20:03:39 -04:00
// Copyright Epic Games, Inc. All Rights Reserved.
using System ;
using System.Collections.Generic ;
using System.Text.Json ;
using System.Text.Json.Serialization ;
using EpicGames.Slack.Elements ;
namespace EpicGames.Slack.Blocks
{
/// <summary>
/// A simple image block, designed to make those cat photos really pop.
/// </summary>
public class ImageBlock : Block
{
/// <summary>
/// The URL of the image to be displayed.Maximum length for this field is 3000 characters.
/// </summary>
2022-08-25 11:12:04 -04:00
[JsonPropertyName("image_url"), JsonPropertyOrder(1)]
2022-08-19 20:03:39 -04:00
public Uri ImageUrl { get ; set ; }
/// <summary>
/// A plain-text summary of the image.This should not contain any markup.Maximum length for this field is 2000 characters.
/// </summary>
2022-08-25 11:12:04 -04:00
[JsonPropertyName("alt_text"), JsonPropertyOrder(2)]
2022-08-19 20:03:39 -04:00
public string AltText { get ; set ; }
/// <summary>
/// An optional title for the image in the form of a text object that can only be of type: plain_text. Maximum length for the text in this field is 2000 characters.
/// </summary>
2022-08-25 11:12:04 -04:00
[JsonPropertyName("title"), JsonPropertyOrder(3)]
2022-08-19 20:03:39 -04:00
public PlainTextObject ? Title { get ; set ; }
/// <summary>
/// Constructor
/// </summary>
public ImageBlock ( Uri imageUrl , string altText , PlainTextObject ? title = null ) : base ( "image" )
{
ImageUrl = imageUrl ;
AltText = altText ;
Title = title ;
}
}
/// <summary>
/// Extension methods for <see cref="ImageBlock"/>
/// </summary>
public static class ImageBlockExtensions
{
/// <summary>
/// Add an <see cref="ImageBlock"/> to the list of blocks
/// </summary>
public static void AddImage ( this ISlackBlockContainer container , Uri imageUrl , string altText , PlainTextObject ? title = null )
{
ImageBlock block = new ImageBlock ( imageUrl , altText , title ) ;
container . Blocks . Add ( block ) ;
}
}
}