-
-
Save cardoso/f47efb9a508fc9fa8fa61a20ee7eb6d9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import AWSLambdaEvents | |
import AWSLambdaRuntime | |
import NIO | |
import Foundation | |
#if canImport(FoundationNetworking) | |
import FoundationNetworking | |
#endif | |
Lambda.run { (context: Lambda.Context, event: APIGateway.Request, callback: @escaping (Result<APIGateway.Response, Error>) -> Void) in | |
context.logger.debug("hello, api gateway!") | |
let botId = "Agent" | |
guard | |
let bodyData = event.body?.data(using: .utf8), | |
let json = try? JSONSerialization.jsonObject(with: bodyData, options: []) as? [String: Any], | |
json["type"] as? String == "message.new", | |
let channelType = json["channel_type"] as? String, | |
let channelId = json["channel_id"] as? String, | |
let message = json["message"] as? [String: Any], | |
let user = message["user"] as? [String: Any], | |
let userId = user["id"] as? String, | |
userId != botId | |
else { | |
callback(.success(APIGateway.Response(statusCode: .ok, body: "nope!"))) | |
return | |
} | |
botReply(channelType: channelType, channelId: channelId, botId: botId) { | |
callback(.success(APIGateway.Response(statusCode: .ok))) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment