setting up twilio function and now going to test

This commit is contained in:
talksik
2022-06-01 19:14:16 -05:00
parent 5d495ebabf
commit e61180d7a6
5 changed files with 129 additions and 5 deletions
@@ -0,0 +1,3 @@
export default class TwilioAccessToken {
constructor(public token: string) {}
}
@@ -0,0 +1 @@
{}
+4 -3
View File
@@ -16,17 +16,18 @@
"main": "lib/index.js",
"dependencies": {
"firebase-admin": "^9.8.0",
"firebase-functions": "^3.14.1"
"firebase-functions": "^3.14.1",
"twilio": "^3.77.2"
},
"devDependencies": {
"@nirvana/core": "*",
"@typescript-eslint/eslint-plugin": "^3.9.1",
"@typescript-eslint/parser": "^3.8.0",
"eslint": "^7.6.0",
"eslint-config-google": "^0.14.0",
"eslint-plugin-import": "^2.22.0",
"firebase-functions-test": "^0.2.0",
"typescript": "^3.8.0",
"@nirvana/core": "*"
"typescript": "^3.8.0"
},
"private": true
}
+38
View File
@@ -1,10 +1,48 @@
import * as functions from 'firebase-functions';
import * as twilio from 'twilio';
import TwilioAccessToken from '../../../core/src/functions/response/TwilioAccessToken.response';
const AccessToken = twilio.jwt.AccessToken;
// // Start writing Firebase Functions
// // https://firebase.google.com/docs/functions/typescript
//
const VideoGrant = AccessToken.VideoGrant;
export const helloWorld = functions.https.onRequest((request, response) => {
functions.logger.info('Hello logs!', { structuredData: true });
response.send('Hello from Firebase!');
});
export const getStreamToken = functions.https.onCall((data, context) => {
// Used when generating any kind of tokens
// To set up environmental variables, see http://twil.io/secure
const twilioAccountSid = process.env.TWILIO_ACCOUNT_SID;
const twilioApiKey = process.env.TWILIO_API_KEY;
const twilioApiSecret = process.env.TWILIO_API_SECRET;
if (!twilioAccountSid || !twilioApiKey || !twilioApiSecret) {
functions.logger.error('no twilio access tokens!!!');
return;
}
const identity = 'user';
// Create Video Grant
const videoGrant = new VideoGrant();
// Create an access token which we will sign and return to the client,
// containing the grant we just created
const token = new AccessToken(twilioAccountSid, twilioApiKey, twilioApiSecret, {
identity: identity,
});
token.addGrant(videoGrant);
functions.logger.info(`${context.auth?.uid} user granted a stream access token`);
// Serialize the token to a JWT string
return new TwilioAccessToken(token.toJwt());
});