-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* DEVEXP-315: Add support for Services (#31) * DEVEXP-316: Add support for Faxes (#32) * DEVEXP-317: Add support for Callbacks (#33) * DEVEXP-320: Add support for Emails (#34)
- Loading branch information
1 parent
d423046
commit 18314b4
Showing
98 changed files
with
3,807 additions
and
659 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
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 |
---|---|---|
|
@@ -6,3 +6,4 @@ | |
.DS_Store | ||
|
||
.env | ||
fax-pdf/ |
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 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 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 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,37 @@ | ||
import { AddEmailToNumbersRequestData } from '@sinch/sdk-core'; | ||
import { | ||
getFaxEmailFromConfig, | ||
getPhoneNumberFromConfig, | ||
getPrintFormat, | ||
initClient, | ||
printFullResponse, | ||
} from '../../config'; | ||
|
||
(async () => { | ||
console.log('*************************'); | ||
console.log('* createEmailForProject *'); | ||
console.log('*************************'); | ||
|
||
const phoneNumber = getPhoneNumberFromConfig(); | ||
const email = getFaxEmailFromConfig(); | ||
|
||
const requestData: AddEmailToNumbersRequestData = { | ||
emailRequestBody: { | ||
email, | ||
phoneNumbers: [ | ||
phoneNumber, | ||
], | ||
}, | ||
}; | ||
|
||
const sinchClient = initClient(); | ||
const response = await sinchClient.fax.emails.addToNumbers(requestData); | ||
|
||
const printFormat = getPrintFormat(process.argv); | ||
|
||
if (printFormat === 'pretty') { | ||
console.log(`Email successfully added to numbers '${response.phoneNumbers?.join(', ')}'`); | ||
} else { | ||
printFullResponse(response); | ||
} | ||
})(); |
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,19 @@ | ||
import { DeleteEmailRequestData } from '@sinch/sdk-core'; | ||
import { getFaxEmailFromConfig, initClient } from '../../config'; | ||
|
||
(async () => { | ||
console.log('***************'); | ||
console.log('* deleteEmail *'); | ||
console.log('***************'); | ||
|
||
const email = getFaxEmailFromConfig(); | ||
|
||
const requestData: DeleteEmailRequestData = { | ||
email, | ||
}; | ||
|
||
const sinchClient = initClient(); | ||
await sinchClient.fax.emails.delete(requestData); | ||
|
||
console.log(`The email '${requestData.email}' has been successfully removed`); | ||
})(); |
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,67 @@ | ||
import { Email, ListEmailsForProjectRequestData, PageResult } from '@sinch/sdk-core'; | ||
import { getPrintFormat, initClient, printFullResponse } from '../../config'; | ||
|
||
const populateEmailsList = ( | ||
emailsPage: PageResult<Email>, | ||
fullEmailsList: Email[], | ||
emailsList: string[], | ||
) => { | ||
fullEmailsList.push(...emailsPage.data); | ||
emailsPage.data.map((email) => { | ||
emailsList.push(`Email '${email.email}' - Phone numbers: '${email.phoneNumbers?.join(', ')}'`); | ||
}); | ||
}; | ||
|
||
(async () => { | ||
console.log('***********************'); | ||
console.log('* getEmailsForProject *'); | ||
console.log('***********************'); | ||
|
||
const requestData: ListEmailsForProjectRequestData = { | ||
pageSize: 2, | ||
}; | ||
|
||
const sinchClient = initClient(); | ||
|
||
// ---------------------------------------------- | ||
// Method 1: Fetch the data page by page manually | ||
// ---------------------------------------------- | ||
let response = await sinchClient.fax.emails.list(requestData); | ||
|
||
// Init data structure to hold the response content | ||
const fullEmailsList: Email[] = []; | ||
// Init data structure to hold the response content for pretty print | ||
const emailsList: string[] = []; | ||
|
||
// Loop on all the pages to get all the emails | ||
let reachedEndOfPages = false; | ||
while (!reachedEndOfPages) { | ||
populateEmailsList(response, fullEmailsList, emailsList); | ||
if (response.hasNextPage) { | ||
response = await response.nextPage(); | ||
} else { | ||
reachedEndOfPages = true; | ||
} | ||
} | ||
|
||
const printFormat = getPrintFormat(process.argv); | ||
|
||
if (printFormat === 'pretty') { | ||
console.log(emailsList.length > 0 | ||
? `List of emails:\n${emailsList.join('\n')}` | ||
: 'Sorry, no emails were found'); | ||
} else { | ||
printFullResponse(fullEmailsList); | ||
} | ||
|
||
// --------------------------------------------------------------------- | ||
// Method 2: Use the iterator and fetch data on more pages automatically | ||
// --------------------------------------------------------------------- | ||
for await (const email of sinchClient.fax.emails.list(requestData)) { | ||
if (printFormat === 'pretty') { | ||
console.log(`Email '${email.email}' - Phone numbers: '${email.phoneNumbers?.join(', ')}'`); | ||
} else { | ||
console.log(email); | ||
} | ||
} | ||
})(); |
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,74 @@ | ||
import { | ||
ListNumbersByEmailRequestData, | ||
PageResult, | ||
ServicePhoneNumber, | ||
} from '@sinch/sdk-core'; | ||
import { getFaxEmailFromConfig, getPrintFormat, initClient, printFullResponse } from '../../config'; | ||
|
||
const populateServiceNumbersList = ( | ||
serviceNumbersPage: PageResult<ServicePhoneNumber>, | ||
fullServiceNumbersList: ServicePhoneNumber[], | ||
serviceNumbersList: string[], | ||
) => { | ||
fullServiceNumbersList.push(...serviceNumbersPage.data); | ||
serviceNumbersPage.data.map((number) => { | ||
serviceNumbersList.push(`Phone numbers: '${number.phoneNumber}'`); | ||
}); | ||
}; | ||
|
||
(async () => { | ||
console.log('*********************'); | ||
console.log('* getNumbersByEmail *'); | ||
console.log('*********************'); | ||
|
||
const email = getFaxEmailFromConfig(); | ||
|
||
const requestData: ListNumbersByEmailRequestData = { | ||
email, | ||
pageSize: 2, | ||
}; | ||
|
||
const sinchClient = initClient(); | ||
|
||
// ---------------------------------------------- | ||
// Method 1: Fetch the data page by page manually | ||
// ---------------------------------------------- | ||
let response = await sinchClient.fax.emails.listNumbers(requestData); | ||
|
||
// Init data structure to hold the response content | ||
const fullServiceNumbersList: ServicePhoneNumber[] = []; | ||
// Init data structure to hold the response content for pretty print | ||
const serviceNumbersList: string[] = []; | ||
|
||
// Loop on all the pages to get all the numbers | ||
let reachedEndOfPages = false; | ||
while (!reachedEndOfPages) { | ||
populateServiceNumbersList(response, fullServiceNumbersList, serviceNumbersList); | ||
if (response.hasNextPage) { | ||
response = await response.nextPage(); | ||
} else { | ||
reachedEndOfPages = true; | ||
} | ||
} | ||
|
||
const printFormat = getPrintFormat(process.argv); | ||
|
||
if (printFormat === 'pretty') { | ||
console.log(serviceNumbersList.length > 0 | ||
? `List of configured numbers for the email '${requestData.email}':\n${serviceNumbersList.join('\n')}` | ||
: 'Sorry, no numbers were found'); | ||
} else { | ||
printFullResponse(fullServiceNumbersList); | ||
} | ||
|
||
// --------------------------------------------------------------------- | ||
// Method 2: Use the iterator and fetch data on more pages automatically | ||
// --------------------------------------------------------------------- | ||
for await (const number of sinchClient.fax.emails.listNumbers(requestData)) { | ||
if (printFormat === 'pretty') { | ||
console.log(`Phone numbers: '${number.phoneNumber}'`); | ||
} else { | ||
console.log(number); | ||
} | ||
} | ||
})(); |
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,38 @@ | ||
import { UpdateEmailRequestData } from '@sinch/sdk-core'; | ||
import { | ||
getFaxEmailFromConfig, | ||
getPhoneNumberFromConfig, | ||
getPrintFormat, | ||
initClient, | ||
printFullResponse, | ||
} from '../../config'; | ||
|
||
(async () => { | ||
console.log('*************************'); | ||
console.log('* createEmailForProject *'); | ||
console.log('*************************'); | ||
|
||
const phoneNumber = getPhoneNumberFromConfig(); | ||
const email = getFaxEmailFromConfig(); | ||
|
||
const requestData: UpdateEmailRequestData = { | ||
email, | ||
updateEmailRequestBody: { | ||
phoneNumbers: [ | ||
phoneNumber, | ||
'+14155552222', | ||
], | ||
}, | ||
}; | ||
|
||
const sinchClient = initClient(); | ||
const response = await sinchClient.fax.emails.update(requestData); | ||
|
||
const printFormat = getPrintFormat(process.argv); | ||
|
||
if (printFormat === 'pretty') { | ||
console.log(`Email successfully updated with numbers '${response.phoneNumbers?.join(', ')}'`); | ||
} else { | ||
printFullResponse(response); | ||
} | ||
})(); |
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,19 @@ | ||
import { DeleteFaxContentRequestData } from '@sinch/sdk-core'; | ||
import { getFaxIdFromConfig, initClient } from '../../config'; | ||
|
||
(async () => { | ||
console.log('************************'); | ||
console.log('* deleteFaxContentById *'); | ||
console.log('************************'); | ||
|
||
const faxId = getFaxIdFromConfig(); | ||
|
||
const requestData: DeleteFaxContentRequestData = { | ||
id: faxId, | ||
}; | ||
|
||
const sinchClient = initClient(); | ||
await sinchClient.fax.faxes.deleteContent(requestData); | ||
|
||
console.log(`The content of the fax with the id '${requestData.id}' has been successfully removed from storage`); | ||
})(); |
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,25 @@ | ||
import { DownloadFaxContentRequestData } from '@sinch/sdk-core'; | ||
import { getFaxIdFromConfig, initClient } from '../../config'; | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
|
||
(async () => { | ||
console.log('******************'); | ||
console.log('* getFaxFileById *'); | ||
console.log('******************'); | ||
|
||
const faxId = getFaxIdFromConfig(); | ||
|
||
const requestData: DownloadFaxContentRequestData = { | ||
id: faxId, | ||
fileFormat: 'pdf', | ||
}; | ||
|
||
const sinchClient = initClient(); | ||
const response = await sinchClient.fax.faxes.downloadContent(requestData); | ||
|
||
const filePath = path.join('./fax-pdf', response.fileName); | ||
fs.writeFileSync(filePath, response.buffer); | ||
|
||
console.log('File successfully downloaded'); | ||
})(); |
Oops, something went wrong.