-
Notifications
You must be signed in to change notification settings - Fork 218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #1414 botMessage handler in Assistant middleware does not work when other event listeners do not exist #1415
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -122,9 +122,12 @@ public EventRequest( | |
JsonObject context = thread.get("context").getAsJsonObject(); | ||
if (context != null) { | ||
AssistantThreadContext threadContext = AssistantThreadContext.builder() | ||
.enterpriseId(context.get("enterprise_id") != null ? context.get("enterprise_id").getAsString() : null) | ||
.teamId(context.get("team_id") != null ? context.get("team_id").getAsString() : null) | ||
.channelId(context.get("channel_id") != null ? context.get("channel_id").getAsString() : null) | ||
// enterprise_id here can be a null value | ||
// others cannot be null as of Jan 2025, but added the same logic to all for future safety | ||
.enterpriseId(context.get("enterprise_id") != null && !context.get("enterprise_id").isJsonNull() ? context.get("enterprise_id").getAsString() : null) | ||
.teamId(context.get("team_id") != null && !context.get("team_id").isJsonNull() ? context.get("team_id").getAsString() : null) | ||
.channelId(context.get("channel_id") != null && !context.get("channel_id").isJsonNull() ? context.get("channel_id").getAsString() : null) | ||
.threadEntryPoint(context.get("thread_entry_point") != null && !context.get("thread_entry_point").isJsonNull() ? context.get("thread_entry_point").getAsString() : null) | ||
.build(); | ||
this.getContext().setThreadContext(threadContext); | ||
} | ||
|
@@ -134,9 +137,12 @@ public EventRequest( | |
// message events (user replies) | ||
this.getContext().setAssistantThreadEvent(true); | ||
this.getContext().setChannelId(event.get("channel").getAsString()); | ||
if (event.get("thread_ts") != null) { | ||
if (event.get("thread_ts") != null | ||
&& !event.get("thread_ts").isJsonNull()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this property cannot be null but for safety... |
||
this.getContext().setThreadTs(event.get("thread_ts").getAsString()); | ||
} else if (event.get("message") != null && event.get("message").getAsJsonObject().get("thread_ts") != null) { | ||
} else if (event.get("message") != null | ||
&& event.get("message").getAsJsonObject().get("thread_ts") != null | ||
&& !event.get("message").getAsJsonObject().get("thread_ts").isJsonNull()) { | ||
// message_changed | ||
this.getContext().setThreadTs(event.get("message").getAsJsonObject().get("thread_ts").getAsString()); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,12 +12,14 @@ | |
private String enterpriseId; | ||
private String teamId; | ||
private String channelId; | ||
private String threadEntryPoint; // "sunroof" etc. | ||
|
||
public Map<String, Object> toMap() { | ||
Map<String, Object> map = new HashMap<>(); | ||
map.put("enterpriseId", this.enterpriseId); | ||
map.put("teamId", this.teamId); | ||
map.put("channelId", this.channelId); | ||
map.put("thread_entry_point", this.threadEntryPoint); | ||
Check warning on line 22 in slack-api-model/src/main/java/com/slack/api/model/assistant/AssistantThreadContext.java Codecov / codecov/patchslack-api-model/src/main/java/com/slack/api/model/assistant/AssistantThreadContext.java#L22
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This property was added recently |
||
return map; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
while testing this change, I found that this pattern could result in a runtime error. I don't think this was the same when we released this feature but the error needs to be eliminated anyway