lantean-code / SlackMessageBuilder

A fluent style builder for creating Slack Messages.
MIT License
2 stars 1 forks source link

Setting response_type for Message #1

Closed rlightner closed 2 years ago

rlightner commented 2 years ago

Use case: Sending a message to a webhook, and need to specify the response_type and not channel is there a way to create a message where the content looks like this:

{
  "response_type": "in_channel",
  "blocks": [{...}]
}
ahjephson commented 2 years ago

If you upgrade to 1.1.2 you'll get support for deriving from SlackMessageBase and you'll be able to use your own implementation to add additional properties.

private sealed class ResponseTypeMessage : SlackMessageBase
{
    public ResponseTypeMessage(IMessageBuilderContext context, string responseType) : base(context)
    {
        ResponseType = responseType;
    }

    [JsonPropertyName("response_type")]
    public string ResponseType { get; }
}

public void CreateDerivedTypeMessage()
{
    var builder = SlackMessageBuilder.CreateMessage<ResponseTypeMessage>(c => new ResponseTypeMessage(c, "in_channel"), "*Fallback*", isMarkdown: true)
        .WithBlocks(b => b.AddHeaderBlock("Header Text"));

    var responseTypeMessage = builder.Build();

    var json = responseTypeMessage.ToJson();
}