feat: introduce twilio auth

This commit is contained in:
Ali BARIN
2021-10-27 20:04:08 +02:00
parent 72476ceb8b
commit 219d24495d
6 changed files with 297 additions and 2 deletions

View File

@@ -0,0 +1,37 @@
import TwilioApi from 'twilio';
import App from '../../models/app';
export default class Twilio {
client: any
connectionData: any
appData: any
constructor(connectionData: any) {
this.client = TwilioApi(connectionData.accountSid, connectionData.authToken);
this.connectionData = connectionData;
this.appData = App.findOneByKey('twilio');
}
async verifyCredentials() {
await this.verify();
return {
screenName: this.connectionData.accountSid
}
}
async verify() {
try {
await this.client.keys.list({ limit: 1 })
return true;
} catch(error) {
// Test credentials throw HTTP 403 and thus, we need to have an exception.
return error?.status === 403;
}
}
async isStillVerified() {
return this.verify();
}
}