[ 
https://issues.apache.org/jira/browse/CAMEL-26023?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Claus Ibsen reassigned CAMEL-26023:
-----------------------------------

    Assignee: Claus Ibsen

> camel-slack - the webhook mode writes camelCase JSON keys and changes the 
> message body
> --------------------------------------------------------------------------------------
>
>                 Key: CAMEL-26023
>                 URL: https://issues.apache.org/jira/browse/CAMEL-26023
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-slack
>    Affects Versions: 4.18.0, 4.22.0, 4.23.0
>            Reporter: Claus Ibsen
>            Assignee: Claus Ibsen
>            Priority: Minor
>             Fix For: 4.24.0
>
>
> Found while checking the body types of the slack component for the catalog 
> (CAMEL-24961).
> h4. 1. The webhook mode writes camelCase JSON keys that Slack ignores
> In webhook mode the producer turns the message into JSON with a plain {{new 
> Gson()}} ({{SlackProducer}}, main 07d2e7a987bc, line 38), which writes the 
> Java field names. Slack expects snake_case keys, so it ignores:
> * {{iconEmoji}} and {{iconUrl}} of the endpoint (Slack reads {{icon_emoji}} 
> and {{icon_url}});
> * for a {{com.slack.api.model.Message}} body, keys such as {{threadTs}}, 
> {{unfurlLinks}} and {{unfurlMedia}}, and in blocks {{imageUrl}} and 
> {{altText}};
> * for a {{SlackMessage}} body, the camelCase keys of its attachments, such as 
> {{authorName}}, {{titleLink}} and {{imageUrl}}.
> Before CAMEL-16255 (Camel 3.9), the producer wrote these keys in snake_case, 
> with the names in {{SlackConstants}}.
> Checked on 4.24.0-SNAPSHOT with {{camel run}} and a fake webhook: the text 
> "Hello text" with {{username=CamelBot&iconEmoji=:camel:}} was posted as 
> {{{"text":"Hello 
> text","channel":"#general","username":"CamelBot","iconEmoji":":camel:"}}}.
> *Proposed change*: write the JSON with the snake_case Gson of the Slack SDK 
> ({{GsonFactory.createSnakeCase()}}), as the token mode effectively does 
> through the SDK.
> h4. 2. The webhook mode changes the message body
> In webhook mode the producer sets the channel and the username of the 
> endpoint, and for a {{SlackMessage}} also its icons, on the message body 
> itself ({{SlackProducer}}, main 07d2e7a987bc, lines 151-163). So the caller's 
> object is changed by the send.
> Checked on 4.24.0-SNAPSHOT with {{camel run}}: after the send, the 
> {{com.slack.api.model.Message}} body had {{channel=#general}} and 
> {{username=CamelBot}}, which it did not have before.
> *Proposed change*: copy the message before it is changed, or set the values 
> on the JSON only.
> h4. Also read in the code, not run
> * The token mode sends only the text of a {{SlackMessage}} body, not its 
> attachments ({{SlackProducer}}, lines 101-108); the webhook mode sends them.
> * The webhook mode catches only IOException and calls {{callback.done(true)}} 
> in a finally block (lines 141-146), so a RuntimeException from 
> {{slack.send}}, such as for an invalid webhookUrl, completes the exchange and 
> is thrown as well.
> * {{SlackCloudEventDataTypeTransformer}} sets the source to "slack." plus a 
> boolean and the subject to {{true}} (lines 49 and 54), and fails with a 
> NullPointerException for no body (line 47).
> _Claude Code on behalf of davsclaus_



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to