lantean-code / SlackMessageBuilder

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

Can't post message using bot with granular permissions & json mapping bug #3

Open andreasnilsen opened 1 year ago

andreasnilsen commented 1 year ago

Using version 1.0.1 of SlackMessageBuilder.SystemTextJson, I receive the following error when posting a SlackApiMessage that is built with any of the WithUsername / WIthIconUrl/ WithIconEmoji methods (all of these methods use setters that also set as_user = false) : {"ok":false,"error":"invalid_arguments","deprecated_argument":"as_user"} The message is posted to the the Slack API /api/chat.postMessage - authenticating using a bot token with granular permissions.

As far as I can understand from https://api.slack.com/methods/chat.postMessage#legacy_authorship , the as_user parameter is only supported for classic slack apps (and webhooks?). There's a similar ticket in the BotKit library, which uses the same api for posting messages - https://github.com/howdyai/botkit/issues/1943 , which they fixed through https://github.com/howdyai/botkit/pull/1944/files

Additionally, if upgrading to version 1.1.2 of the package, serialization of such messages fails due to the post_at field name being used for both the Username and PostAt properties: https://github.com/lantean-code/SlackMessageBuilder/blame/18ad8915a3e36fa2efa0fc5a7b5b484ffcc16cc7/SlackMessageBuilder/Objects/SlackApiMessage.cs#L179

simendsjo commented 1 week ago

The latter issue is fixed by https://github.com/lantean-code/SlackMessageBuilder/commit/b22ba92118d80195ba15e29a984aee36876497b4