Example #1
0
        public async Task <APIGatewayProxyResponse> Connect(APIGatewayProxyRequest request, ILambdaContext context)
        {
            context.Logger.Log($"connected: {request.RequestContext?.ConnectionId}");
            await _dynamoDbContext.SaveAsync(new WebSocketConnection
            {
                ConnectionId = request.RequestContext.ConnectionId,
                Connected    = "true"
            });

            return(new APIGatewayProxyResponse
            {
                StatusCode = 200
            });
        }
        public async Task <APIGatewayProxyResponse> PostMessage(APIGatewayProxyRequest request, ILambdaContext context)
        {
            var cancellationTokenSource = new CancellationTokenSource();
            var message = JsonConvert.DeserializeObject <Message>(request.Body);

            await _dynamoDbContext.SaveAsync(message, cancellationTokenSource.Token);

            await _amazonIotData.PublishAsync(new PublishRequest
            {
                Topic   = $"CHAT/Messages",
                Qos     = 1,
                Payload = new MemoryStream(
                    Encoding.UTF8.GetBytes(request.Body))
            }, cancellationTokenSource.Token);

            return(_responseWrapper.Success(message));
        }