Skip to content

Commit 218393f

Browse files
author
Tony Bedford
authored
Fix dispatch code snippets (#80)
* Fixed dispatch code snippets * Various fixes * Add gitignore for local testing * Rename files * Fixes
1 parent 69471dd commit 218393f

10 files changed

+289
-184
lines changed

dispatch/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package.json
2+
package-lock.json
3+
node_modules/
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
require("dotenv").config({ path: __dirname + "/../.env" });
2+
3+
const TO_NUMBER = process.env.TO_NUMBER;
4+
const FROM_NUMBER = process.env.FROM_NUMBER;
5+
const FB_SENDER_ID = process.env.FB_SENDER_ID;
6+
const FB_RECIPIENT_ID = process.env.FB_RECIPIENT_ID;
7+
8+
const NEXMO_API_KEY = process.env.NEXMO_API_KEY;
9+
const NEXMO_API_SECRET = process.env.NEXMO_API_SECRET;
10+
const NEXMO_APPLICATION_ID = process.env.NEXMO_APPLICATION_ID;
11+
const NEXMO_APPLICATION_PRIVATE_KEY_PATH =
12+
__dirname + "/../" + process.env.NEXMO_APPLICATION_PRIVATE_KEY_PATH;
13+
14+
const Nexmo = require("nexmo");
15+
16+
const nexmo = new Nexmo({
17+
apiKey: NEXMO_API_KEY,
18+
apiSecret: NEXMO_API_SECRET,
19+
applicationId: NEXMO_APPLICATION_ID,
20+
privateKey: NEXMO_APPLICATION_PRIVATE_KEY_PATH
21+
});
22+
23+
nexmo.dispatch.create(
24+
"failover",
25+
[
26+
{
27+
from: { type: "messenger", id: FB_SENDER_ID },
28+
to: { type: "messenger", id: FB_RECIPIENT_ID },
29+
message: {
30+
content: {
31+
type: "text",
32+
text: "Dispatch API: Message 1"
33+
}
34+
},
35+
failover: {
36+
expiry_time: 60,
37+
condition_status: "read"
38+
}
39+
},
40+
{
41+
from: { type: "sms", number: FROM_NUMBER },
42+
to: { type: "sms", number: TO_NUMBER },
43+
message: {
44+
content: {
45+
type: "text",
46+
text: "Dispatch API: Message 2"
47+
}
48+
}
49+
}
50+
],
51+
(err, data) => {
52+
if (err) {
53+
console.log("logging after error !!!", err);
54+
} else {
55+
console.log(data.dispatch_uuid);
56+
}
57+
}
58+
);

dispatch/send-failover-mms-sms.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
require("dotenv").config({ path: __dirname + "/../.env" });
2+
3+
const TO_NUMBER = process.env.TO_NUMBER;
4+
const FROM_NUMBER = process.env.FROM_NUMBER;
5+
const IMG_URL = process.env.IMG_URL;
6+
7+
const NEXMO_API_KEY = process.env.NEXMO_API_KEY;
8+
const NEXMO_API_SECRET = process.env.NEXMO_API_SECRET;
9+
const NEXMO_APPLICATION_ID = process.env.NEXMO_APPLICATION_ID;
10+
const NEXMO_APPLICATION_PRIVATE_KEY_PATH =
11+
__dirname + "/../" + process.env.NEXMO_APPLICATION_PRIVATE_KEY_PATH;
12+
13+
const Nexmo = require("nexmo");
14+
15+
const nexmo = new Nexmo({
16+
apiKey: NEXMO_API_KEY,
17+
apiSecret: NEXMO_API_SECRET,
18+
applicationId: NEXMO_APPLICATION_ID,
19+
privateKey: NEXMO_APPLICATION_PRIVATE_KEY_PATH
20+
});
21+
22+
nexmo.dispatch.create(
23+
"failover",
24+
[
25+
{
26+
from: { type: "mms", number: FROM_NUMBER },
27+
to: { type: "mms", number: TO_NUMBER },
28+
message: {
29+
content: {
30+
type: "image",
31+
image: { url: IMG_URL }
32+
}
33+
},
34+
failover: {
35+
expiry_time: 60,
36+
condition_status: "read"
37+
}
38+
},
39+
{
40+
from: { type: "sms", number: FROM_NUMBER },
41+
to: { type: "sms", number: TO_NUMBER },
42+
message: {
43+
content: {
44+
type: "text",
45+
text: "Dispatch API: Message 2"
46+
}
47+
}
48+
}
49+
],
50+
(err, data) => {
51+
if (err) {
52+
console.log("logging after error !!!");
53+
} else {
54+
console.log(data.dispatch_uuid);
55+
}
56+
}
57+
);

dispatch/send-failover-sms-facebook.js

Lines changed: 0 additions & 46 deletions
This file was deleted.

dispatch/send-failover-sms-mms.js

Lines changed: 0 additions & 46 deletions
This file was deleted.

dispatch/send-failover-sms-sms.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
require("dotenv").config({ path: __dirname + "/../.env" });
2+
3+
const TO_NUMBER_1 = process.env.TO_NUMBER_1;
4+
const TO_NUMBER_2 = process.env.TO_NUMBER_2;
5+
const FROM_NUMBER = process.env.FROM_NUMBER;
6+
7+
const NEXMO_API_KEY = process.env.NEXMO_API_KEY;
8+
const NEXMO_API_SECRET = process.env.NEXMO_API_SECRET;
9+
const NEXMO_APPLICATION_ID = process.env.NEXMO_APPLICATION_ID;
10+
const NEXMO_APPLICATION_PRIVATE_KEY_PATH =
11+
__dirname + "/../" + process.env.NEXMO_APPLICATION_PRIVATE_KEY_PATH;
12+
13+
const Nexmo = require("nexmo");
14+
15+
const nexmo = new Nexmo({
16+
apiKey: NEXMO_API_KEY,
17+
apiSecret: NEXMO_API_SECRET,
18+
applicationId: NEXMO_APPLICATION_ID,
19+
privateKey: NEXMO_APPLICATION_PRIVATE_KEY_PATH
20+
});
21+
22+
nexmo.dispatch.create(
23+
"failover",
24+
[
25+
{
26+
from: { type: "sms", number: FROM_NUMBER },
27+
to: { type: "sms", number: TO_NUMBER_1 },
28+
message: {
29+
content: {
30+
type: "text",
31+
text: "Dispatch API: Message 1"
32+
}
33+
},
34+
failover: {
35+
expiry_time: 60,
36+
condition_status: "read"
37+
}
38+
},
39+
{
40+
from: { type: "sms", number: FROM_NUMBER },
41+
to: { type: "sms", number: TO_NUMBER_2 },
42+
message: {
43+
content: {
44+
type: "text",
45+
text: "Dispatch API: Message 2"
46+
}
47+
}
48+
}
49+
],
50+
(err, data) => {
51+
if (err) {
52+
console.log("logging after error !!!", err);
53+
} else {
54+
console.log(data.dispatch_uuid);
55+
}
56+
}
57+
);

dispatch/send-failover-sms-viber.js

Lines changed: 0 additions & 46 deletions
This file was deleted.

dispatch/send-failover-sms-whatsapp.js

Lines changed: 0 additions & 46 deletions
This file was deleted.

0 commit comments

Comments
 (0)