Claus Ibsen created CAMEL-27681:
-----------------------------------

             Summary: camel-slack: consumer NPE for IM, empty token, maxResults 
type, option labels and flags
                 Key: CAMEL-27681
                 URL: https://issues.apache.org/jira/browse/CAMEL-27681
             Project: Camel
          Issue Type: Bug
          Components: camel-slack
            Reporter: Claus Ibsen
             Fix For: 4.24.0


Found while improving the option descriptions of camel-slack for CAMEL-23832 
(commit 
https://github.com/apache/camel/commit/ad7845d3fe0a319681dad10b8ab4323f51f8d249).
These are separate problems of the component; the descriptions commit only 
documents the current behavior.

h4. 1. The consumer cannot read a direct message (conversationType=IM)
{{SlackConsumer.getChannelId()}} finds the conversation with 
{{it.getName().equals(channel)}} among the conversations of 
{{conversations.list}}. Direct-message conversations ({{IM}}) have no name, so 
{{Conversation.getName()}} is null and the consumer fails to start with a 
{{NullPointerException}} instead of reading the conversation or reporting that 
it is not found.
Proposed change: compare null-safe ({{channel.equals(it.getName())}}), and for 
{{IM}} match the conversation by the user ID ({{Conversation.getUser()}}) or 
accept a conversation ID as channel.

h4. 2. An empty token with a webhookUrl posts with the empty token
{{SlackEndpoint.createProducer()}} checks the token with 
{{ObjectHelper.isEmpty(token)}}, but {{SlackProducer.process()}} picks the 
token mode on {{getToken() != null}}. With an empty token (for example a 
property placeholder that resolves to an empty value) and a webhookUrl, the 
producer calls {{chat.postMessage}} with the empty token and fails, instead of 
posting to the webhook.
Proposed change: use {{ObjectHelper.isNotEmpty(getToken())}} in 
{{SlackProducer.process()}}.

h4. 3. maxResults is a String option
{{maxResults}} is declared as {{String}} (default {{10}}), but 
{{SlackConsumer.conversationsHistory()}} parses it with {{Integer.parseInt}} at 
every poll. A value that is not a number is accepted when the endpoint is 
created and fails at every poll; tooling shows it as text instead of a number.
Proposed change: make it an {{int}} option (the setter can keep accepting a 
String through the type converter).

h4. 4. serverUrl has the label consumer
{{serverUrl}} is labeled {{consumer}}, but {{SlackProducer.doStart()}} also 
passes it to {{SlackHelper.createSlackConfig()}}, so the producer uses it in 
token mode.
Proposed change: label it {{common}}.

h4. 5. username is marked secret
The deprecated {{username}} option has {{security = "secret"}}, but it is the 
display name of the message author, so it is masked in logs and tooling for no 
reason.
Proposed change: remove {{security = "secret"}}.

h4. 6. The labels of the component options token and webhookUrl
The component options {{token}} and {{webhookUrl}} have the labels {{token}} 
and {{webhook}}, while the endpoint options have {{common}} and {{producer}}. 
The component options are grouped differently from all other components.
Proposed change: use the labels of the endpoint options.

_Claude Code on behalf of davsclaus_



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

Reply via email to