Skip to content

Instantly share code, notes, and snippets.

@kuschanton
Created May 19, 2022 09:58
Show Gist options
  • Save kuschanton/1e66cc5980fe6f5f57b5fb3d4abc6d45 to your computer and use it in GitHub Desktop.
Save kuschanton/1e66cc5980fe6f5f57b5fb3d4abc6d45 to your computer and use it in GitHub Desktop.
// Imports global types
import '@twilio-labs/serverless-runtime-types'
// Fetches specific types
import {
Context,
ServerlessCallback,
ServerlessFunctionSignature,
} from '@twilio-labs/serverless-runtime-types/types'
type OptOut = {
Body: string,
From: string
}
export const handler: ServerlessFunctionSignature<{}, OptOut> = function (
context: Context,
event: OptOut,
callback: ServerlessCallback,
) {
const response = new Twilio.Response()
response.setStatusCode(200)
if (event.Body === 'STOP') {
console.log('We\'ve got opt-out', event)
context.getTwilioClient()
.sync
.services('ISf4a436efb334298119ada8ecd755902a')
.syncLists('ES5972b0b60648407fb073084b6c37e658')
.syncListItems
.create({
data: {
phoneNumber: event.From,
},
})
.then(listItem => {
console.log('Successfully stored list item')
callback(null, response)
})
.catch(err => {
console.log(err)
callback(null, response)
},
)
} else {
callback(null, response)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment