Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(templates): add number-activity, number-usage template #522

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
603 changes: 603 additions & 0 deletions number-activity/assets/index.html

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions number-activity/assets/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
pre {
white-space: pre-wrap;
word-wrap: break-word;
}

.alert {
padding: 15px;
margin-top: 10px;
border: 1px solid transparent;
border-radius: 4px;
}

.alert-info {
border-color: #bce8f1;
color: #31708f;
background-color: #d9edf7;
word-wrap: break-word;
}

.alert-error {
color: #a94442;
background-color: #f2dede;
border-color: #ebccd1;
}
17 changes: 17 additions & 0 deletions number-activity/functions/get_account.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
exports.handler = async function (context, event, callback) {
let finalData = null;
const accountSid = { acc: process.env.ACCOUNT_SID };

if (event.request.headers.authorization !== process.env.Password) {
finalData = { er: 0 };
return callback(null, finalData);
}
try {
return callback(null, accountSid);
} catch (error) {
console.error(error.message);
response.setStatusCode(error.status || 400);
response.setBody({ error: error.message });
return callback(null, response);
}
};
53 changes: 53 additions & 0 deletions number-activity/functions/listNumbers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
exports.handler = async function (context, event, callback) {
let finalData = null;
let resp = null;
let pageResp = null;
let str = '';
const accountSid = process.env.ACCOUNT_SID;
const authToken = process.env.AUTH_TOKEN;
const subAccount = event.subAcc;
const client = require('twilio')(accountSid, authToken, {
accountSid: subAccount,
});

const response = new Twilio.Response();
response.appendHeader('Content-Type', 'application/json');

if (event.request.headers.authorization !== process.env.Password) {
finalData = { er: 0 };
return callback(null, finalData);
}
try {
if (event.number !== undefined) {
pageResp = await client.incomingPhoneNumbers.list({
limit: 1,
phoneNumber: event.number,
});

str = JSON.stringify(pageResp).length;
if (str < 3) {
response.setStatusCode(200);
response.setBody('number not found');
return callback(null, response);
}

return callback(null, pageResp);
} else if (event.pageSize > 0) {
pageResp = await client.incomingPhoneNumbers.page({
pageSize: event.pageSize,
Page: event.page,
pageToken: event.pageToken,
});

return callback(null, pageResp);
}
aaa;

Check failure on line 44 in number-activity/functions/listNumbers.js

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, current)

Expected an assignment or function call and instead saw an expression

Check failure on line 44 in number-activity/functions/listNumbers.js

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, lts/*)

Expected an assignment or function call and instead saw an expression
resp = await client.incomingPhoneNumbers.list();
return callback(null, resp);
} catch (error) {
console.error(error.message);
response.setStatusCode(error.status || 400);
response.setBody({ error: error.message });
return callback(null, response);
}
};
15 changes: 15 additions & 0 deletions number-activity/functions/mask_account.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
exports.handler = async function (context, event, callback) {
const masked =
String(process.env.ACCOUNT_SID).slice(0, 28).replace(/./g, '*') +
String(process.env.ACCOUNT_SID).slice(-6);
const accountSid = { acc: masked };

try {
return callback(null, accountSid);
} catch (error) {
console.error(error.message);
response.setStatusCode(error.status || 400);
response.setBody({ error: error.message });
return callback(null, response);
}
};
Loading
Loading