jellyfin / jellyfin-plugin-webhook

GNU General Public License v3.0
141 stars 45 forks source link

Slack Notification Failing #186

Open conors06 opened 1 year ago

conors06 commented 1 year ago

Is there a way to fix this? Jellyfin with Docker Compose

[2023-08-24 20:15:59.634 +00:00] [WRN] [43] Jellyfin.Plugin.Webhook.Destinations.Slack.SlackClient: Notification failed with response status code BadRequest: "invalid_payload"
[2023-08-24 20:15:59.674 +00:00] [WRN] [43] Jellyfin.Plugin.Webhook.Destinations.Slack.SlackClient: Notification failed with "POST" request to https://hooks.slack.com/services/T04SLM9KKGE/xxxxxxxx/rF8bZzwaza9K5AZCXnTLZYRn: "{
        \"username\": \"Jellyfin\",
        \"icon_url\": \"https://camo.githubusercontent.com/674eb841cc63bf5031bca2654ccff6f66db3c51554074324ad369f9c460ce7d6/68747470733a2f2f63646e2e6a7364656c6976722e6e65742f67682f77616c6b78636f64652f64617368626f6172642d69636f6e732f706e672f6a656c6c7966696e2e706e67\",

[2023-08-24 20:52:43.706 +00:00] [DBG] [32] Jellyfin.Plugin.Webhook.Destinations.Slack.SlackClient: SendAsync Body: ""
[2023-08-24 20:52:43.798 +00:00] [WRN] [27] Jellyfin.Plugin.Webhook.Destinations.Slack.SlackClient: Notification failed with "POST" request to https://hooks.slack.com/services/T04SLM9KKGE/xxxxxxx/pIRf6UqEmsesigYxtJr4M7nb: ""
[2023-08-24 20:52:43.798 +00:00] [WRN] [27] Jellyfin.Plugin.Webhook.Destinations.Slack.SlackClient: Notification failed with response status code BadRequest: "invalid_payload"
[2023-08-24 20:52:44.353 +00:00] [ERR] [27] Jellyfin.Plugin.Webhook.WebhookSender: Unable to send notification
System.Text.Json.JsonException: The input does not contain any JSON tokens. Expected the input to start with a valid JSON token, when isFinalBlock is true. Path: $ | LineNumber: 0 | BytePositionInLine: 0.
 ---> System.Text.Json.JsonReaderException: The input does not contain any JSON tokens. Expected the input to start with a valid JSON token, when isFinalBlock is true. LineNumber: 0 | BytePositionInLine: 0.
   at System.Text.Json.ThrowHelper.ThrowJsonReaderException(Utf8JsonReader& json, ExceptionResource resource, Byte nextByte, ReadOnlySpan`1 bytes)
   at System.Text.Json.Utf8JsonReader.Read()
   at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
   --- End of inner exception stack trace ---
   at System.Text.Json.ThrowHelper.ReThrowWithPath(ReadStack& state, JsonReaderException ex)
   at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
   at System.Text.Json.JsonSerializer.ReadFromSpan[TValue](ReadOnlySpan`1 utf8Json, JsonTypeInfo jsonTypeInfo, Nullable`1 actualByteCount)
   at System.Text.Json.JsonSerializer.ReadFromSpan[TValue](ReadOnlySpan`1 json, JsonTypeInfo jsonTypeInfo)
   at System.Text.Json.JsonSerializer.Deserialize[TValue](String json, JsonSerializerOptions options)
   at Jellyfin.Plugin.Webhook.Destinations.GenericForm.GenericFormClient.SendAsync(GenericFormOption option, Dictionary`2 data)
   at Jellyfin.Plugin.Webhook.WebhookSender.SendNotification[T](IWebhookClient`1 webhookClient, T option, Dictionary`2 itemData, Type itemType)
[2023-08-24 20:52:44.354 +00:00] [DBG] [27] Jellyfin.Plugin.Webhook.Destinations.Slack.SlackClient: SendAsync Body: ""
[2023-08-24 20:52:44.456 +00:00] [WRN] [27] Jellyfin.Plugin.Webhook.Destinations.Slack.SlackClient: Notification failed with "POST" request to https://hooks.slack.com/services/T04SLM9KKGE/xxxxxxx/pIRf6UqEmsesigYxtJr4M7nb: ""
[2023-08-24 20:52:44.457 +00:00] [WRN] [27] Jellyfin.Plugin.Webhook.Destinations.Slack.SlackClient: Notification failed with response status code BadRequest: "invalid_payload"
crobibero commented 1 year ago

The json that is you posted is invalid. Please provide the template you are using.

conors06 commented 1 year ago
{
{{#if_exist SlackUsername}}
"username": "{{BotUsername}}",
{{/if_exist}}
{{#if_exist SlackIconUrl}}
"icon_url": "{{SlackIconUrl}}",
{{/if_exist}}
{{#if_equals ItemType 'Season'}}
"text": "{{{SeriesName}}} {{{Name}}} has been added to {{{ServerName}}}",
{{else}}
{{#if_equals ItemType 'Episode'}}
"text": "{{{SeriesName}}} S{{SeasonNumber00}}E{{EpisodeNumber00}} {{{Name}}} has been added to {{{ServerName}}}",
{{else}}
"text": "{{{Name}}} ({{Year}}) has been added to {{{ServerName}}}",
{{/if_equals}}
{{/if_equals}}
}

It's just the template slack one

crobibero commented 1 year ago

I believe your slack icon url is what is causing issues, looks like it has a trailing backslash

conors06 commented 1 year ago

Tried it with different icon image and no icon didn't work either way

Aadityajoshi151 commented 1 year ago

I am also facing a similar issue: @crobibero Did you find a solution?

[12:15:14] [WRN] [18] Jellyfin.Plugin.Webhook.Destinations.Slack.SlackClient: Notification failed with POST request to https://hooks.slack.com/services/xxxxxxxxxxxx/xxxxxxxxxxxxxxxxxxxxxxxxxxxxx: {
    "token": "",
    "user": "", 

        "message": "John started playing: Looney.Tunes.Cartoons.S05E30 ()"
}
[12:15:14] [WRN] [18] Jellyfin.Plugin.Webhook.Destinations.Slack.SlackClient: Notification failed with response status code BadRequest: no_text

I am not using an icon url. Here is the template I am using:

{
    "token": "{{Token}}",
    "user": "{{UserToken}}",    

    {{#if_equals NotificationType "PlaybackStart"}}
            {{#if_equals ItemType 'Episode'}}
        "message": "{{NotificationUsername}} started playing show:\n\n{{SeriesName}} ({{Year}})\nS{{SeasonNumber00}}E{{EpisodeNumber00}} - {{Name}}"
        {{/if_equals}}

        {{#if_equals ItemType 'Movie'}}
        "message": "{{NotificationUsername}} started playing movie: {{Name}} ({{Year}})"
        {{/if_equals}}
    {{/if_equals}}  
}
crobibero commented 1 year ago

@Aadityajoshi151 Are token and user populated when being sent?

Aadityajoshi151 commented 1 year ago

@crobibero No, they are not.

crobibero commented 1 year ago

I would start there. You need to add the details so Slack knows you are authorized to send messages.

Aadityajoshi151 commented 1 year ago

Got it. With some trial and error I was able to get the notifications working. It looks like I got templates for Discord and Slack mixed up. Here is the working template (for slack) if someone is interested:

{
    {{#if_exist SlackUsername}}
        "username": "{{BotUsername}}",
    {{/if_exist}}
    {{#if_exist SlackIconUrl}}
        "icon_url": "{{SlackIconUrl}}",
    {{/if_exist}}
{{#if_equals NotificationType "PlaybackStart"}}
    {{#if_equals ItemType 'Season'}}
        "text": "{{{NotificationUsername}}} started watching {{{SeriesName}}} {{{Name}}}",
    {{else}}
        {{#if_equals ItemType 'Episode'}}
            "text": "{{{NotificationUsername}}} started watching {{{SeriesName}}} S{{SeasonNumber00}}E{{EpisodeNumber00}} {{{Name}}}",
        {{else}}
            "text": "{{{NotificationUsername}}} started watching {{{Name}}} ({{Year}})",
        {{/if_equals}}
    {{/if_equals}}
{{/if_equals}}
}