I'm sorry, but I've watched all seven of Jennifer Person's videos, read the documentation, and worked through the tutorials but I still don't see how to write my function. I'm trying to write a function that gets an IBM Watson Speech-to-text token, which is obtained with this CURL script:
curl -X GET --user username:password --output token
"https://stream.watsonplatform.net/authorization/api/v1/token?url=https://stream.watsonplatform.net/speech-to-text/api"
I.e., send an HTTP GET request to the URL, provide my username and password, and then write the output to the file /javascript/services/token
.
This is my guess as to the function. An authentication trigger wraps a Nodejs HTTP GET request, and a NodeJs file save fs.writefile
.
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.getWatsonToken = functions.auth.user().onCreate(event => { // authentication trigger
var https = require('https'); // Nodejs http.request
var options = {
host: 'stream.watsonplatform.net',
path: '/authorization/api/v1/token?url=https://stream.watsonplatform.net/speech-to-text/api',
username: groucho,
password: swordfish
};
callback = function(response) {
response.on('end', function () {
console.log(response);
fs.writeFile("/javascript/services/token", response);
});
}
http.request(options, callback).end();
});