freeclimb-request-types
TypeScript icon, indicating that this package has built-in type declarations

2.0.9 • Public • Published

freeclimb-request-types

freeclimb-request-types is a package adding typescript support for freeclimb application webhooks.

Installing

npm isntall freeclimb-request-types

or

yarn install freeclimb-request-types

Getting Started

import express, { Request } from 'express';
import {InboundCallBody} from "freeclimb-request-types";
import bodyParser from 'body-parser';

const app = express()
app.use(bodyParser.json());
const port = 3000

// Tells the code that the request body will of InboundCallBody type
app.post('/callEntry', (req: Request<{}, {}, InboundCallBody>, res) => {
  req.body.callId; // $ExpectType string

  res.send([{
    Say: {
      text: `The number you called is ${req.body.to}`
    }
  }])
})

app.listen(port, () => {
  console.log(`Example app listening on port ${port}`)
})

in addition type guards are also available

import {isInboundCall} from "freeclimb-request-types";

app.post('/callEntry', (req, res) => {

  if(isInboundCall(req.body)) {
    res.send([{
      Say: {
        text: `The number you called is ${req.body.to}`
      }
    }]);
  } else {
    res.status(400).send('Invalid request');
  }
});

Readme

Keywords

Package Sidebar

Install

npm i freeclimb-request-types

Weekly Downloads

49

Version

2.0.9

License

MIT

Unpacked Size

47.2 kB

Total Files

7

Last publish

Collaborators

  • coffee-rabit