Skip to content

Commit a7b2a1c

Browse files
committed
updates
1 parent a524de5 commit a7b2a1c

File tree

5 files changed

+59
-14
lines changed

5 files changed

+59
-14
lines changed

components/esendex/actions/send-sms-message/send-sms-message.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
key: "esendex-send-sms-message",
66
name: "Send SMS Message",
77
description: "Send an SMS message to a recipient. [See the documentation[(https://developers.esendex.com/api-reference/#messagedispatcher)",
8-
version: "0.0.{{ts}}",
8+
version: "0.0.1",
99
type: "action",
1010
props: {
1111
esendex,
@@ -70,7 +70,7 @@ export default {
7070
],
7171
},
7272
});
73-
$.export("$summary", `Successfully sent SMSmessage to ${this.to}`);
73+
$.export("$summary", `Successfully sent SMS message to ${this.to}`);
7474
return response;
7575
},
7676
};

components/esendex/actions/send-voice-message/send-voice-message.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
key: "esendex-send-voice-message",
66
name: "Send Voice Message",
77
description: "Send a voice message to a recipient. [See the documentation[(https://developers.esendex.com/api-reference/#messagedispatcher)",
8-
version: "0.0.{{ts}}",
8+
version: "0.0.1",
99
type: "action",
1010
props: {
1111
esendex,

components/esendex/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"access": "public"
1414
},
1515
"dependencies": {
16-
"@pipedream/platform": "^3.0.3"
16+
"@pipedream/platform": "^3.0.3",
17+
"simple-xml2json": "^1.2.3"
1718
}
1819
}

components/esendex/sources/new-message-received/new-message-received.mjs

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import esendex from "../../esendex.app.mjs";
22
import constants from "../../common/constants.mjs";
33
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
4+
import xml2json from "simple-xml2json";
5+
import sampleEmit from "./test-event.mjs";
46

57
export default {
68
key: "esendex-new-message-received",
79
name: "New Message Received",
810
description: "Emit new event when a new message is received. [See the documentation[(https://developers.esendex.com/api-reference/#messageheader)",
9-
version: "0.0.{{ts}}",
11+
version: "0.0.1",
1012
type: "source",
1113
dedupe: "unique",
1214
props: {
@@ -21,7 +23,7 @@ export default {
2123
type: {
2224
type: "string",
2325
label: "Type",
24-
description: "The type of the messages to watch for: either SMS or Voice. If no type is specified, the default is SMS.",
26+
description: "The type of the messages to watch for: either SMS or Voice. If no type is specified, all types are returned.",
2527
options: constants.MESSAGE_TYPES,
2628
optional: true,
2729
},
@@ -35,35 +37,47 @@ export default {
3537
},
3638
methods: {
3739
_getLastTs() {
38-
return this.$db.get("lastTs");
40+
return this.db.get("lastTs");
3941
},
4042
_setLastTs(ts) {
41-
this.$db.set("lastTs", ts);
43+
this.db.set("lastTs", ts);
4244
},
4345
generateMeta(message) {
4446
return {
45-
id: message.reference,
46-
summary: `New Message Received: ${message.reference}`,
47+
id: message.id,
48+
summary: `New Message Received: ${message.id}`,
4749
ts: Date.parse(message.laststatusat),
4850
};
4951
},
5052
async processEvent(max) {
5153
const lastTs = this._getLastTs();
5254
let maxTs = lastTs;
5355

54-
const { messageheaders } = await this.esendex.listMessages({
56+
const xmlResponse = await this.esendex.listMessages({
5557
params: {
5658
start: lastTs,
5759
finish: new Date().toISOString()
5860
.split(".")[0] + "Z", // current time
59-
type: this.type,
6061
status: this.status,
6162
},
6263
});
6364

65+
const { messageheaders } = xml2json.parser(xmlResponse);
66+
let messages = messageheaders?.messageheader || [];
67+
if (!Array.isArray(messages)) {
68+
messages = [
69+
messages,
70+
];
71+
}
72+
73+
if (!messages.length) {
74+
return;
75+
}
76+
6477
let count = 0;
65-
for (const message of messageheaders) {
66-
if (!lastTs || Date.parse(message.laststatusat) > Date.parse(lastTs)) {
78+
for (const message of messages) {
79+
if ((!lastTs || Date.parse(message.laststatusat) > Date.parse(lastTs))
80+
&& (!this.type || message.type === this.type)) {
6781
const meta = this.generateMeta(message);
6882
this.$emit(message, meta);
6983
if (!maxTs || Date.parse(message.laststatusat) > Date.parse(maxTs)) {
@@ -86,4 +100,5 @@ export default {
86100
async run() {
87101
await this.processEvent();
88102
},
103+
sampleEmit,
89104
};
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
export default {
2+
"id": "7645199a-01e6-4a9f-8ce1-ae3a4ea30227",
3+
"uri": "https://api.esendex.com/v1.0/messageheaders/7645199a-01e6-4a9f-8ce1-ae3a4ea30227",
4+
"reference": "EX0349711",
5+
"status": "Delivered",
6+
"deliveredat": "2025-06-04T15:21:39.783Z",
7+
"sentat": "2025-06-04T15:21:34.19Z",
8+
"laststatusat": "2025-06-04T15:21:39.783Z",
9+
"submittedat": "2025-06-04T15:21:33.843Z",
10+
"type": "SMS",
11+
"to": {
12+
"phonenumber": 5555555555,
13+
},
14+
"from": {
15+
"phonenumber": 5555555555,
16+
},
17+
"summary": "hello world",
18+
"body": {
19+
"id": "7645199a-01e6-4a9f-8ce1-ae3a4ea30227",
20+
"uri": "https://api.esendex.com/v1.0/messageheaders/7645199a-01e6-4a9f-8ce1-ae3a4ea30227/body"
21+
},
22+
"direction": "Outbound",
23+
"parts": 1,
24+
"username": "",
25+
"batch": {
26+
"id": "3428f958-c19d-49c6-9c59-3c2f9e884713",
27+
"uri": "https://api.esendex.com/v1.0/messagebatches/3428f958-c19d-49c6-9c59-3c2f9e884713"
28+
}
29+
}

0 commit comments

Comments
 (0)