Skip to content
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

Bambda: Extract JSON data from WebSocket message, add it to Notes #55

Merged
merged 2 commits into from
Jan 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions Proxy/WS/ExtractPayloadToNotes.bambda
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Extracts JSON elements from the WebSocket message and displays it in the "Notes" column of the WebSocket History tab
*
* @author Nick Coblentz (https://github.com/ncoblentz)
*
**/

//The bambda will search for json elements with the following keys. The keys below are just examples. Add the keys you want to include here:
List<String> terms = List.of("target","error");

if (!message.annotations().hasNotes()) {
StringBuilder builder = new StringBuilder();
String payload = utilities().byteUtils().convertToString(message.payload().getBytes());
terms.forEach(term -> {
Matcher m = Pattern.compile("\"" + term + "\":\"([^\"]+)\"", Pattern.CASE_INSENSITIVE).matcher(payload);
while (m.find() && m.groupCount() > 0) {
for (int i = 1; i <= m.groupCount(); i++) {
if (m.group(i) != null)
builder.append(term + ": " + m.group(i) + " ");
}
}
});
message.annotations().setNotes(builder.toString());
}
return true;