Skip to content

Commit d86534d

Browse files
authored
Merge pull request #1 from KyMidd/feature/add-plaintext-snippet-support
add plaintext snippet support
2 parents 5031f0d + f4cc5d8 commit d86534d

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

python/devopsbot.py

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,27 @@ def build_conversation_content(payload, token):
351351
}
352352
)
353353

354+
# Support plaintext snippets
355+
elif file["mimetype"] in ["text/plain"]:
356+
# File is a supported type
357+
snippet_file_url = file["url_private_download"]
358+
359+
# Fetch the file and continue
360+
snippet_file_object = requests.get(
361+
snippet_file_url, headers={"Authorization": "Bearer " + token}
362+
)
363+
364+
# Decode the file into plaintext
365+
snippet_text = snippet_file_object.content.decode("utf-8")
366+
367+
# Append the file to the content array
368+
content.append(
369+
{
370+
"type": "text",
371+
"text": f"{speaker_name} ({pronouns}) attached a snippet of text:\n\n{snippet_text}",
372+
}
373+
)
374+
354375
# If the mime type is not supported, set unsupported_file_type_found to True
355376
else:
356377
print(f"Unsupported file type found: {file['mimetype']}")
@@ -546,19 +567,19 @@ def lambda_handler(event, context):
546567
# Isolate body
547568
event_body = isolate_event_body(event)
548569

549-
# Check for duplicate event or trash messages, return 200 and exit if detected
550-
if check_for_duplicate_event(event["headers"], event_body["event"]):
551-
return generate_response(
552-
200, "❌ Detected a re-send or edited message, exiting"
553-
)
554-
555570
# Special challenge event for Slack. If receive a challenge request, immediately return the challenge
556571
if "challenge" in event_body:
557572
return {
558573
"statusCode": 200,
559574
"body": json.dumps({"challenge": event_body["challenge"]}),
560575
}
561576

577+
# Check for duplicate event or trash messages, return 200 and exit if detected
578+
if check_for_duplicate_event(event["headers"], event_body["event"]):
579+
return generate_response(
580+
200, "❌ Detected a re-send or edited message, exiting"
581+
)
582+
562583
# Print the event
563584
print("🚀 Event:", event)
564585

@@ -596,7 +617,7 @@ def handle_message_events(client, body, say, req):
596617
return slack_handler.handle(event, context)
597618

598619

599-
# Main function
620+
# Main function, primarily for local development
600621
if __name__ == "__main__":
601622

602623
# Run in local development mode

0 commit comments

Comments
 (0)