Skip to content

Commit

Permalink
update express-messaging callback events type usage
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasassisrosa committed Oct 9, 2024
1 parent 6cbe24e commit 69998f4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 22 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/express-messaging.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: CI
name: CI express-messaging

on:
push:
Expand Down
24 changes: 11 additions & 13 deletions express-messaging/messaging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,19 @@ router
.route("/inbound")
.post(async function inboundMessageController(req, res) {
res.sendStatus(200); // Play nice and respond to webhook
const event = req.body.data;
console.log(`Received inbound message with ID: ${event.payload.id}`);
const event = (req.body as Telnyx.events.InboundMessageEvent).data!;
console.log(`Received inbound message with ID: ${event.payload?.id}`);
const dlrUrl = new URL(
"/messaging/outbound",
`${req.protocol}://${req.hostname}`
).href;
const toNumber = event.payload.to[0].phone_number as string;
const fromNumber = event.payload["from"].phone_number as string;
const medias = event.payload.media;
const mediaPromises: Promise<string>[] = medias.map(
async (media: { url: string }) => {
const fileName = await downloadFile(media.url);
return uploadFile(fileName);
}
);
const toNumber = event.payload?.to?.at(0)?.phone_number as string;
const fromNumber = event.payload?.from?.phone_number as string;
const medias = event.payload?.media || [];
const mediaPromises: Promise<string>[] = medias.map(async (media) => {
const fileName = await downloadFile(media.url!);
return uploadFile(fileName);
});
const mediaUrls = await Promise.all(mediaPromises);
try {
const messageRequest: Telnyx.MessagesCreateOptionalParams = {
Expand All @@ -96,8 +94,8 @@ router
.route("/outbound")
.post(async function outboundMessageController(req, res) {
res.sendStatus(200); // Play nice and respond to webhook
const event = req.body.data;
console.log(`Received message DLR with ID: ${event.payload.id}`);
const event = (req.body as Telnyx.events.OutboundMessageEvent).data!;
console.log(`Received message DLR with ID: ${event.payload?.id}`);
});

export default router;
8 changes: 4 additions & 4 deletions express-messaging/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion express-messaging/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"axios": "^1.7.7",
"dotenv": "^16.4.0",
"express": "^4.21.1",
"telnyx": "2.0.0-alpha.6"
"telnyx": "2.0.0-alpha.7"
},
"devDependencies": {
"@types/express": "^5.0.0",
Expand Down

0 comments on commit 69998f4

Please sign in to comment.