Skip to content

Commit

Permalink
chore: removing express dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
tiwarishubham635 committed Jan 29, 2024
1 parent 7bbaaba commit 390d849
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 38 deletions.
41 changes: 40 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,46 @@ To use a custom HTTP client with this helper library, please see the [advanced e

### Use webhook validation

See [example](examples/express.js) for a code sample for incoming Twilio request validation.
Following code sample can be referred for incoming Twilio request validation.
```js
const twilio = require("twilio");
const bodyParser = require("body-parser");
const MessagingResponse = require("twilio").twiml.MessagingResponse;

const authToken = process.env.TWILIO_AUTH_TOKEN;

const express = require("express");
const app = express();
const port = 3000;

app.use(
bodyParser.json({
verify: (req, res, buf) => {
req.rawBody = buf;
},
})
);

app.get("/", (req, res) => {
res.send("Hello World!");
});

app.post("/message", twilio.webhook(authToken), (req, res) => {
// Twilio Messaging URL - receives incoming messages from Twilio
const response = new MessagingResponse();

response.message(`Your text to me was ${req.body.Body}.
Webhooks are neat :)`);

res.set("Content-Type", "text/xml");
res.send(response.toString());
});

app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`);
});

```

## Docker image

Expand Down
36 changes: 0 additions & 36 deletions examples/express.js

This file was deleted.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
"@types/url-parse": "^1.4.8",
"babel-plugin-replace-ts-export-assignment": "^0.0.2",
"eslint": "^8.31.0",
"express": "^4.17.1",
"jest": "^29.5.5",
"jshint": "^2.11.0",
"mock-fs": "^5.2.0",
Expand Down

0 comments on commit 390d849

Please sign in to comment.