Lambda to receive HTTP POST with JSON payload

I’m working on building an SMS platform, so part of this is for the SMS gateway to forward the SMS to a public URL with a JSON Payload (which I have no control of the format) so I need to have it accepted by a lambda in Slash and then from there insert it as a record in the Graph database for later processing.

The SMS gateway will send an HTTP POST with JSON payload to the lambda function.

How can I do this with Slash?

I have deployed this type:

type InboundSMS  {
  id: String! @id
  dateTime: String!
  destinationAddress: String!
  messageId: String!
  message: String!
  resourceURL: String!
  senderAddress: String!

As the schema for the incoming SMS with JSON format:


            "dateTime":"Fri Nov 22 2013 12:12:13 GMT+0000 (UTC)",

You will need to have a server/lambda function (outside of Slash) to intercept the POST payload, then transform it into a GraphQL mutation to Slash.

Alternatively, if you CAN pre-wrap the POST payload into a GraphQL mutation, and you really want to push the limits of your mind-bending abilities of designing a serverless architecture, you can also try something like this:

First, define a “RawJSON” type:

type Raw {
    id: ID!
    raw: String!
    msg: InboundSMS

Then write a new mutation:

type Mutation {
     newRaw(raw: String!): ID! @lambda

Then write your function:

async function foo({args, graphql}){
    sideeffects = await graphql( `mutation ($id: String ...) { 
       addInboundSMS(...) { ... } // GraphQL mutation to addInboundSMS
    }`, {"id": ___, /*your arguments here */})
    result = await graphql(`mutation {
        addRaw (...) { raw { id } ... } // GraphQL mutation to addRaw
    }`, {/*your arguments here */})

// register your function
    "Mutation.newRaw": foo

Something like that. The tricky bit is to transform your POST payload into a GraphQL mutation. That needs to be done somewhere (either clientside, or another server intercepting the POST and re-post to Slash)

1 Like