Skip to content

Commit

Permalink
add numbers example
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasassisrosa committed Jan 21, 2025
1 parent 324128e commit d601c0a
Show file tree
Hide file tree
Showing 8 changed files with 1,557 additions and 0 deletions.
9 changes: 9 additions & 0 deletions examples/numbers/.eslintrc.js
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',
},
};
1 change: 1 addition & 0 deletions examples/numbers/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20.17.0
2 changes: 2 additions & 0 deletions examples/numbers/.tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
nodejs 20.17.0
npm 10.8.1
9 changes: 9 additions & 0 deletions examples/numbers/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Node SDK Example - Numbers

To test this run `npm install` and then run the main script in `package.json` with `ts-node`:

```bash
npm run start
```

> don't forget to populate your Telnyx API Key with `export TELNYX_API_KEY=KEY...`
29 changes: 29 additions & 0 deletions examples/numbers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* To run this file, just provide your Secret API Key, like so:
* TELNYX_API_KEY=KEY... node index.js
*/

import Telnyx from 'telnyx';

const telnyx = new Telnyx(process.env.TELNYX_API_KEY || '');

const params: Telnyx.AvailablePhoneNumbersListParams = {
'filter[features]': ['sms', 'emergency', 'mms', 'international_sms'],
'filter[limit]': 10,
'filter[country_code]': 'US',
};

(async function numbers() {
try {
const {data: numbers} = await telnyx.availablePhoneNumbers.list(params);

console.log(numbers);
} catch (e: unknown) {
console.error(e);

const rawError: Telnyx.TelnyxRawError = (e as {raw: Telnyx.TelnyxRawError})
.raw;

console.dir(JSON.stringify(rawError.errors));
}
})();
26 changes: 26 additions & 0 deletions examples/numbers/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "telnyx-numbers-example",
"version": "1.0.0",
"description": "",
"main": "index.ts",
"scripts": {
"debug": "tsx index.ts",
"start": "tsx index.ts"
},
"author": "Telnyx <[email protected]> (https://telnyx.com)",
"license": "ISC",
"type": "module",
"engines": {
"node": "^18 || >=20"
},
"dependencies": {
"telnyx": "2.0.0-beta.5"
},
"devDependencies": {
"@types/node": "^22.7.4",
"tsx": "^4.19.1",
"typescript": "^5.6.2",
"typescript-eslint": "^8.8.0"
},
"packageManager": "[email protected]+sha512.b8fef5494bd3fe4cbd4edabd0745df2ee5be3e4b0b8b08fa643aa3e4c6702ccc0f00d68fa8a8c9858a735a0032485a44990ed2810526c875e416f001b17df12b"
}
Loading

0 comments on commit d601c0a

Please sign in to comment.