-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update express-texml-call-mask to Typescript (#28)
* update express-texml-call-mask to Typescript * update phone numbers table example * use texml translator * update package deps
- Loading branch information
1 parent
e28d961
commit af866e0
Showing
17 changed files
with
2,961 additions
and
6,557 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: CI express-texml-call-mask | ||
|
||
on: | ||
push: | ||
branches: [master] | ||
paths: | ||
- "express-texml-call-mask/**" | ||
pull_request: | ||
branches: [master] | ||
paths: | ||
- "express-texml-call-mask/**" | ||
|
||
jobs: | ||
type-check: | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
working-directory: express-texml-call-mask | ||
strategy: | ||
matrix: | ||
node-version: [18.x, 20.x, 22.x] | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- run: npm ci | ||
- run: npm run type-check |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module.exports = { | ||
parserOptions: { | ||
ecmaVersion: 6, | ||
}, | ||
rules: { | ||
'new-cap': 'off', | ||
'no-console': 'off', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
20.17.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
nodejs 20.17.0 | ||
npm 10.8.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import express from "express"; | ||
import Telnyx from "telnyx"; | ||
import * as db from "../models/db"; | ||
import * as texml from "../packages/texml"; | ||
|
||
const router = express.Router(); | ||
|
||
type TelnyxTexmlTranslatorGatherCallback = { | ||
AccountSid: string; | ||
CallSid: string; | ||
CallSidLegacy: string; | ||
Digits: string; | ||
From: string; | ||
To: string; | ||
}; | ||
|
||
router | ||
.route("/inbound") | ||
.post<{}, unknown, Telnyx.events.CallEvent>(async (req, res) => { | ||
const gatherSentence = | ||
"Hello, please enter the phone number with country code you would like to dial followed by the pound sign"; | ||
const event = req.body; | ||
console.log(event); | ||
|
||
res.type("application/xml"); | ||
res.send(texml.gatherTeXML(gatherSentence, "#", 10, 15)); | ||
}); | ||
|
||
router | ||
.route("/gather") | ||
.post<{}, unknown, TelnyxTexmlTranslatorGatherCallback>(async (req, res) => { | ||
const event = req.body; | ||
console.log(event); | ||
const phoneNumber = event.Digits; | ||
const userRecord = db.lookupUserByPSTNPhoneNumber(event.From); | ||
|
||
// Connect inbound caller to conf | ||
// Create outbound dial to desired PSTN number | ||
// when that call answers, add to conf | ||
// save conf-id | ||
// every {duration} play audio to conf-id | ||
|
||
res.type("application/xml"); | ||
res.send( | ||
texml.dialTeXML( | ||
`${userRecord?.telnyxPhoneNumber}`, | ||
"/dialFinished", | ||
"POST", | ||
"record-from-answer-dual", | ||
"recordFinished", | ||
`+${phoneNumber}` | ||
) | ||
); | ||
}); | ||
|
||
router.route("/dialFinished").post(async (req, res) => { | ||
const event = req.body; | ||
console.log(event); | ||
res.sendStatus(200); | ||
}); | ||
|
||
router.route("/recordFinished").post(async (req, res) => { | ||
const event = req.body; | ||
console.log(event); | ||
res.type("application/xml"); | ||
res.send(texml.hangupTeXML("Thank you for the call, hanging up")); | ||
}); | ||
|
||
export default router; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import "dotenv/config"; | ||
import http from "http"; | ||
import express from "express"; | ||
import dtmfDialController from "./controllers/dtmfDialController"; | ||
|
||
const app = express(); | ||
const httpServer = http.createServer(app); | ||
|
||
app.use(express.json()); | ||
|
||
app.get("/", (_req, res) => { | ||
res.send("Hello World 👋 🌎"); | ||
}); | ||
|
||
const dtmfDialPath = "/dtmfDial"; | ||
app.use( | ||
dtmfDialPath, | ||
express.urlencoded({ extended: true }), | ||
dtmfDialController | ||
); | ||
|
||
const port = process.env.PORT || 3000; | ||
httpServer.listen(port); | ||
console.log(`Server listening on port: ${port}`); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import phoneNumbersTable from "./phoneNumbersTable.json"; | ||
|
||
export const lookupUserByPSTNPhoneNumber = (phoneNumber: string) => | ||
phoneNumbersTable.filter((row) => row.pstnPhoneNumber === phoneNumber).at(0); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[ | ||
{ | ||
"pstnPhoneNumber": "+1...", | ||
"telnyxPhoneNumber": "+1..." | ||
} | ||
] |
Oops, something went wrong.