Skip to content

Commit 32eb1c5

Browse files
authored
Merge pull request #8 from KyMidd/feature/receiver-pattern2
Receiver pattern
2 parents 800c0e2 + c44f16d commit 32eb1c5

File tree

3 files changed

+100
-40
lines changed

3 files changed

+100
-40
lines changed

python/receiver.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import json
2+
import os
3+
import boto3
4+
5+
# Initialize AWS Lambda client
6+
lambda_client = boto3.client('lambda')
7+
8+
def lambda_handler(event, context):
9+
"""
10+
Receives Slack events, performs basic validation, and asynchronously invokes the processor Lambda
11+
"""
12+
print("Received event: %s", json.dumps(event))
13+
14+
try:
15+
# Parse the event body
16+
body = json.loads(event['body'])
17+
18+
# Handle Slack URL verification challenge
19+
if 'challenge' in body:
20+
return {
21+
'statusCode': 200,
22+
'body': json.dumps({'challenge': body['challenge']})
23+
}
24+
25+
# Get the event type
26+
event_type = body.get('type', '')
27+
28+
# Check for edited messages
29+
if (
30+
event_type == 'event_callback' and
31+
'edited' in body.get('event', {})
32+
):
33+
print('Detected edited message, discarding')
34+
return {
35+
'statusCode': 200,
36+
'body': json.dumps({'message': 'Edited message discarded'})
37+
}
38+
39+
# Only process events we care about
40+
if event_type == 'event_callback':
41+
# Asynchronously invoke the processor Lambda
42+
lambda_client.invoke(
43+
FunctionName=os.environ['PROCESSOR_FUNCTION_NAME'],
44+
InvocationType='Event', # Async invocation
45+
Payload=json.dumps(event)
46+
)
47+
48+
# Always return 200 OK to Slack quickly
49+
return {
50+
'statusCode': 200,
51+
'body': json.dumps({'message': 'Event received'})
52+
}
53+
54+
except Exception as e:
55+
print("Error processing event: %s", str(e))
56+
# Still return 200 to Slack to prevent retries
57+
return {
58+
'statusCode': 200,
59+
'body': json.dumps({'message': 'Error processing event'})
60+
}

slack_bot/slack_bot_manifest.json

Lines changed: 0 additions & 40 deletions
This file was deleted.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"display_information": {
3+
"name": "MyDevOpsBot"
4+
},
5+
"features": {
6+
"bot_user": {
7+
"display_name": "MyDevOpsBot",
8+
"always_online": false
9+
}
10+
},
11+
"oauth_config": {
12+
"scopes": {
13+
"bot": [
14+
"app_mentions:read",
15+
"channels:history",
16+
"chat:write",
17+
"files:read",
18+
"groups:history",
19+
"im:history",
20+
"im:read",
21+
"links:read",
22+
"users:read"
23+
]
24+
}
25+
},
26+
"settings": {
27+
"event_subscriptions": {
28+
"bot_events": [
29+
"app_mention",
30+
"message.im"
31+
]
32+
},
33+
"interactivity": {
34+
"is_enabled": true
35+
},
36+
"org_deploy_enabled": false,
37+
"socket_mode_enabled": true,
38+
"token_rotation_enabled": false
39+
}
40+
}

0 commit comments

Comments
 (0)