Skip to content

Commit 2bc9447

Browse files
authored
Merge pull request #93 from messagebird/fix/typos-and-remove-sandbox
fix: typos and remove sandbox
2 parents 6b58dd9 + 1129435 commit 2bc9447

File tree

7 files changed

+191
-2440
lines changed

7 files changed

+191
-2440
lines changed

README.md

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ Messaging and Voice API use different pagination semantics:
8181

8282
````javascript
8383
// list conversations
84-
//In this case 20 is limit and 0 is offset
84+
// In this case 20 is limit and 0 is offset
8585
messagebird.conversations.list(20, 0, function (err, response) {
8686
if (err) {
8787
return console.log(err);
@@ -108,19 +108,19 @@ Verifying Signatures
108108

109109
For each HTTP request that MessageBird sends, a `MessageBird-Signature-JWT` header is added.
110110

111-
The `MessageBird-Signature-JWT` header is a signature that consists of all the information that is required to verify the integrity of the request. The signature is generated from the request URL and request body and is signed with the HMAC-SHA256 algorithm using your your signing key. You can validate this signature using our SDKsto e nsure that the request is valid and unaltered. The token also includes timestamp claims that allow you to prove the time of the request, protecting from replay attacks and the like.
112-
For more details consult the [documentation](https://developers.messagebird.com/api/#verifying-http-requests).
111+
The `MessageBird-Signature-JWT` header is a signature that consists of all the information that is required to verify the integrity of the request. The signature is generated from the request URL and request body and is signed with the HMAC-SHA256 algorithm using your your signing key. You can validate this signature using our SDKsto ensure that the request is valid and unaltered. The token also includes timestamp claims that allow you to prove the time of the request, protecting from replay attacks and the like.
112+
For more details consult the [documentation](https://developers.messagebird.com/api/#verifying-http-requests).
113113

114114
Examples:
115+
115116
- [full example with Express](./examples/webhook-signature-express-middleware.js)
116117
- [example in vanilla JS](./examples/webhook-signature-http-node.js)
117118

118-
119119
Let's use Express Signature middleware to verify webhooks.
120120

121121
```javascript
122122
// This example show how to verify the authenticity of a MessageBird webhook.
123-
const mbWebookSignatureJwt = require('messagebird/lib/webhook-signature-jwt');
123+
const mbWebhookSignatureJwt = require('messagebird/lib/webhook-signature-jwt');
124124
const express = require('express');
125125

126126
const secret = '<YOUR SIGNING KEY>';
@@ -132,7 +132,7 @@ const app = express();
132132
app.set('trust proxy', () => true);
133133

134134
// Replace <YOUR_SIGNING_KEY> with your actual signing key.
135-
const verifySignature = new mbWebookSignatureJwt.ExpressMiddlewareVerify(secret);
135+
const verifySignature = new mbWebhookSignatureJwt.ExpressMiddlewareVerify(secret);
136136

137137
// Retrieve the raw body as a buffer.
138138
app.use(express.raw({ 'type': '*/*' }));
@@ -146,9 +146,6 @@ app.post('/webhook', verifySignature, (req, res) => {
146146
});
147147
```
148148

149-
150-
151-
152149
Documentation
153150
-------------
154151

examples/webhook-signature-express-middleware.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// This example show how to verify the authenticity of a MessageBird webhook.
2-
const mbWebookSignatureJwt = require('messagebird/lib/webhook-signature-jwt');
2+
const mbWebhookSignatureJwt = require('messagebird/lib/webhook-signature-jwt');
33
const express = require('express');
44

55
const secret = '<YOUR SIGNING KEY>';
@@ -11,7 +11,7 @@ const app = express();
1111
app.set('trust proxy', () => true);
1212

1313
// Replace <YOUR_SIGNING_KEY> with your actual signing key.
14-
const verifySignature = new mbWebookSignatureJwt.ExpressMiddlewareVerify(secret);
14+
const verifySignature = new mbWebhookSignatureJwt.ExpressMiddlewareVerify(secret);
1515

1616
// Retrieve the raw body as a buffer.
1717
app.use(express.raw({ 'type': '*/*' }));
@@ -32,10 +32,10 @@ app.post('/webhook', verifySignature, (req, res) => {
3232
// However it doesn't verify if the URL was altered or not.
3333
//
3434
// This shouldn't be used in a production system and when used no query parameters should be trusted.
35-
const skipUrlOpts = new mbWebookSignatureJwt.VerifyOptions();
35+
const skipUrlOpts = new mbWebhookSignatureJwt.VerifyOptions();
3636

3737
skipUrlOpts.validateUrl = false;
38-
let skipUrlVerifySignature = new mbWebookSignatureJwt.ExpressMiddlewareVerify(secret, skipUrlOpts);
38+
let skipUrlVerifySignature = new mbWebhookSignatureJwt.ExpressMiddlewareVerify(secret, skipUrlOpts);
3939

4040
app.get('/webhook-skip-url-verification', skipUrlVerifySignature, (req, res) => {
4141
res.send('partialy verified');
@@ -46,7 +46,7 @@ app.get('/webhook-skip-url-verification', skipUrlVerifySignature, (req, res) =>
4646
// By default jti is required but always considered valid.
4747
//
4848
// Do note that the following implementation isn't production-grade and only for demonstration purposes.
49-
const verifyJtiOpts = new mbWebookSignatureJwt.VerifyOptions();
49+
const verifyJtiOpts = new mbWebhookSignatureJwt.VerifyOptions();
5050
const seenJtis = new Set();
5151

5252
skipUrlOpts.jwtVerifyJti = (jti) => {
@@ -56,7 +56,7 @@ skipUrlOpts.jwtVerifyJti = (jti) => {
5656
seenJtis.add(jti);
5757
return true;
5858
};
59-
const verifyJtiVerifySignature = new mbWebookSignatureJwt.ExpressMiddlewareVerify(secret, verifyJtiOpts);
59+
const verifyJtiVerifySignature = new mbWebhookSignatureJwt.ExpressMiddlewareVerify(secret, verifyJtiOpts);
6060

6161
app.get('/webhook-verify-jti', verifyJtiVerifySignature, (req, res) => {
6262
res.send('verified with jti');

examples/webhook-signature-http-node.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const mbWebookSignatureJwt = require('messagebird/lib/webhook-signature-jwt');
1+
const mbWebhookSignatureJwt = require('messagebird/lib/webhook-signature-jwt');
22
const http = require('http');
33
const { createSecretKey } = require('crypto');
44

@@ -30,9 +30,9 @@ const server = http.createServer((req, res) => {
3030
.then(() => {
3131
let body = Buffer.concat(chunks);
3232
let url = `${getProtocol(req)}://${req.headers.host}${req.url}`;
33-
let jwt = req.headers[mbWebookSignatureJwt.SIGNATURE_HEADER_NAME];
33+
let jwt = req.headers[mbWebhookSignatureJwt.SIGNATURE_HEADER_NAME];
3434

35-
return mbWebookSignatureJwt.verify(
35+
return mbWebhookSignatureJwt.verify(
3636
url,
3737
body,
3838
jwt,

lib/messagebird.js

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,11 @@ module.exports = function (accessKey, timeout, features) {
2424
timeout: timeout || 5000
2525
};
2626

27-
var CONVERSATIONSENDPOINT = 'conversations.messagebird.com';
27+
var CONVERSATIONS_ENDPOINT = 'conversations.messagebird.com';
2828
var VOICE_ENDPOINT = 'voice.messagebird.com';
2929
var IS_FIREBASE_PLUGIN_ENABLED = false;
3030

3131
if (features && 'indexOf' in features) {
32-
if (features.indexOf('ENABLE_CONVERSATIONSAPI_WHATSAPP_SANDBOX') !== -1) {
33-
CONVERSATIONSENDPOINT = 'whatsapp-sandbox.messagebird.com';
34-
}
3532
if (features.indexOf('ENABLE_FIREBASE_PLUGIN') !== -1) {
3633
IS_FIREBASE_PLUGIN_ENABLED = true;
3734
}
@@ -608,7 +605,7 @@ module.exports = function (accessKey, timeout, features) {
608605

609606
conversations: {
610607
getEndpoint: function () {
611-
return CONVERSATIONSENDPOINT;
608+
return CONVERSATIONS_ENDPOINT;
612609
},
613610

614611
/**
@@ -623,7 +620,7 @@ module.exports = function (accessKey, timeout, features) {
623620
*/
624621
send: function (params, callback) {
625622
httpRequest({
626-
hostname: CONVERSATIONSENDPOINT,
623+
hostname: CONVERSATIONS_ENDPOINT,
627624
method: 'POST',
628625
path: '/v1/send',
629626
params: params
@@ -642,7 +639,7 @@ module.exports = function (accessKey, timeout, features) {
642639
*/
643640
start: function (params, callback) {
644641
httpRequest({
645-
hostname: CONVERSATIONSENDPOINT,
642+
hostname: CONVERSATIONS_ENDPOINT,
646643
method: 'POST',
647644
path: '/v1/conversations/start',
648645
params: params
@@ -672,7 +669,7 @@ module.exports = function (accessKey, timeout, features) {
672669
}
673670

674671
httpRequest({
675-
hostname: CONVERSATIONSENDPOINT,
672+
hostname: CONVERSATIONS_ENDPOINT,
676673
method: 'GET',
677674
path: '/v1/conversations',
678675
params: params
@@ -688,7 +685,7 @@ module.exports = function (accessKey, timeout, features) {
688685
*/
689686
read: function (id, callback) {
690687
httpRequest({
691-
hostname: CONVERSATIONSENDPOINT,
688+
hostname: CONVERSATIONS_ENDPOINT,
692689
method: 'GET',
693690
path: '/v1/conversations/' + id
694691
}, callback);
@@ -704,7 +701,7 @@ module.exports = function (accessKey, timeout, features) {
704701
*/
705702
update: function (id, params, callback) {
706703
httpRequest({
707-
hostname: CONVERSATIONSENDPOINT,
704+
hostname: CONVERSATIONS_ENDPOINT,
708705
method: 'PATCH',
709706
path: '/v1/conversations/' + id,
710707
params: params
@@ -722,7 +719,7 @@ module.exports = function (accessKey, timeout, features) {
722719
*/
723720
reply: function (id, params, callback) {
724721
httpRequest({
725-
hostname: CONVERSATIONSENDPOINT,
722+
hostname: CONVERSATIONS_ENDPOINT,
726723
method: 'POST',
727724
path: '/v1/conversations/' + id + '/messages',
728725
params: params
@@ -751,7 +748,7 @@ module.exports = function (accessKey, timeout, features) {
751748
}
752749

753750
httpRequest({
754-
hostname: CONVERSATIONSENDPOINT,
751+
hostname: CONVERSATIONS_ENDPOINT,
755752
method: 'GET',
756753
path: '/v1/conversations/' + id + '/messages',
757754
params: params
@@ -767,7 +764,7 @@ module.exports = function (accessKey, timeout, features) {
767764
*/
768765
readMessage: function (id, callback) {
769766
httpRequest({
770-
hostname: CONVERSATIONSENDPOINT,
767+
hostname: CONVERSATIONS_ENDPOINT,
771768
method: 'GET',
772769
path: '/v1/messages/' + id
773770
}, callback);
@@ -784,7 +781,7 @@ module.exports = function (accessKey, timeout, features) {
784781
*/
785782
create: function (params, callback) {
786783
httpRequest({
787-
hostname: CONVERSATIONSENDPOINT,
784+
hostname: CONVERSATIONS_ENDPOINT,
788785
method: 'POST',
789786
path: '/v1/webhooks',
790787
params: params
@@ -800,7 +797,7 @@ module.exports = function (accessKey, timeout, features) {
800797
*/
801798
read: function (id, callback) {
802799
httpRequest({
803-
hostname: CONVERSATIONSENDPOINT,
800+
hostname: CONVERSATIONS_ENDPOINT,
804801
method: 'GET',
805802
path: '/v1/webhooks/' + id
806803
}, callback);
@@ -816,7 +813,7 @@ module.exports = function (accessKey, timeout, features) {
816813
*/
817814
update: function (id, params, callback) {
818815
httpRequest({
819-
hostname: CONVERSATIONSENDPOINT,
816+
hostname: CONVERSATIONS_ENDPOINT,
820817
method: 'PATCH',
821818
path: '/v1/webhooks/' + id,
822819
params: params
@@ -844,7 +841,7 @@ module.exports = function (accessKey, timeout, features) {
844841
}
845842

846843
httpRequest({
847-
hostname: CONVERSATIONSENDPOINT,
844+
hostname: CONVERSATIONS_ENDPOINT,
848845
method: 'GET',
849846
path: '/v1/webhooks',
850847
params: params
@@ -860,7 +857,7 @@ module.exports = function (accessKey, timeout, features) {
860857
*/
861858
delete: function (id, callback) {
862859
httpRequest({
863-
hostname: CONVERSATIONSENDPOINT,
860+
hostname: CONVERSATIONS_ENDPOINT,
864861
method: 'DELETE',
865862
path: '/v1/webhooks/' + id
866863
}, callback);

0 commit comments

Comments
 (0)