Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
exports.dorothyCares = functions.https.onRequest((request, response) => {
// 1. declaring our app so that we can make requests
const app = new App({
request,
response
});
// 2. Logging the request
console.log('Request headers: ' + JSON.stringify(request.headers));
console.log('Request body: ' + JSON.stringify(request.body));
function giveRessources(app) {
// Keeping track of the version of the function that will be deployed
console.log('give ressources v1.5');
let technology = app.getArgument(TECH_ARGUMENT);
// make the request to our api to have the informations
console.log('https://dorothycares.herokuapp.com/ressources/' + technology);
https.get('https://dorothycares.herokuapp.com/ressources/' + technology, (res) => {
// declaring the body
let body = '';
const receive = (node, config, req, res) => {
let json = req.body
// try { json = JSON.parse(json); } catch (ex) { console.log('Parsing Error', ex, json) }
let app = new DialogflowApp({request: req, response: res});
if(json.originalRequest == undefined) {
console.log(json);
node.warn('Empty request received');
return;
}
let data = botmgr.buildMessageFlow({ message : json }, {
userLocale: 'message.originalRequest.data.user.locale',
userId: 'message.originalRequest.data.user.userId',
convId: 'message.originalRequest.data.conversation.conversationId',
payload: 'message.originalRequest.data.inputs[0].rawInputs[0].query',
inputType: 'message.originalRequest.data.inputs[0].rawInputs[0].inputType',
source: CARRIER
})
app.post('/', (req, res) => {
// grab the ledState value from the Dialogflow webhook
const assistant = new DialogflowApp({
request: req,
response: res
});
// define the action map of responses
const actionMap = new Map();
actionMap.set(NAME_ACTION, responseHandler);
// ask Assistant to respond accordingly
assistant.handleRequest(actionMap);
});
const initialize = (req, res) => {
// Our main app website should pass along an extra var with Dialogflow request letting us know
// where its coming from. Lacking this variable means coming from Home, Dialogflow, Web Simulator etc
let requestFromFrontend =
(req.body.originalRequest && req.body.originalRequest["source"] && req.body.originalRequest["source"] === "frontend") || false;
if (requestFromFrontend) {
// frontend doesn't yet need any fancy processing, pass the result along from Dialogflow straight back to frontend
// so they can handle on their own
res.send(req.body);
} else if (req.body.result) {
// we have a result so lets process all this good stuff
new DialogflowApp({ request: req, response: res }).handleRequest(app => {
logDebug("handleWebhook() result", req.body.result.fulfillment, req.body.result);
logDebug("handleWebhook() originalRequest", req.body.originalRequest);
if (req.body.originalRequest && req.body.originalRequest.data && isHealthCheck(req.body.originalRequest.data)) {
// send original body through so we don't create anything in datastore
logDebug("isHealthCheck() true - exiting.");
return res.send(JSON.stringify(req.body));
}
let action = app.getIntent();
if (action === "input.unknown") {
handleFallback(req, res);
} else if (action.includes("followup.")) {
handleFollowups(app, req.body, res);
} else {
function testDialogflow(request: express.Request, response: express.Response) {
const app = new DialogflowApp({request, response});
const actionMap = new Map();
actionMap.set(app.StandardIntents.MAIN, () => {
const order: Transactions.Order = app.buildOrder('foo');
app.askForTransactionDecision(order, {
type: app.Transactions.PaymentType.PAYMENT_CARD,
displayName: 'VISA-1234',
deliveryAddressRequired: true
});
});
app.handleRequest(actionMap);
}
expressApp.post('/', (request, response) => {
const app = new DialogflowApp({request: request, response: response});
console.log('Request headers: ' + JSON.stringify(request.headers));
console.log('Request body: ' + JSON.stringify(request.body));
const WELCOME_INTENT = 'input.welcome';
const UNKNOWN_INTENT = 'input.unknown';
const DIRECTION_INTENT = 'input.directions';
const DIRECTION_ARGUMENT = 'Directions';
const LOOK_INTENT = 'input.look';
const runner = runnerFactory(story, app);
if (runner === null) {
throw new Error('Runner not found!');
}
const welcomeIntent = (app) => {
console.log('welcomeIntent');
runner.started = app.data.hasOwnProperty('restore');
exports.waterLog = functions.https.onRequest((request, response) => {
console.log('Request headers: ' + JSON.stringify(request.headers));
console.log('Request body: ' + JSON.stringify(request.body));
//Initialise app dependencies
const dialogflowApp = new DialogflowApp({request, response});
const userManager = new UserManager(firebaseAdmin);
const timeManager = new TimeManager(firebaseAdmin, geoTz, moment);
const waterLog = new WaterLog(firebaseAdmin, timeManager);
const factsRepository = new FactsRepository(dialogflowApp);
const chatbase = ChatbaseFactory
.setApiKey(process.env.MY_CHATBASE_KEY)
.setPlatform('GoogleAssistant')
.setUserId(dialogflowApp.getUser().userId);
const analytics = new Analytics(chatbase);
const conversation = new Conversation(dialogflowApp, userManager, waterLog, timeManager, factsRepository, analytics);
//Define map of Dialogflow agent Intents
let actionMap = new Map();
exports.triviaGame = functions.https.onRequest((request, response) => {
logger.info(logObject('trivia', 'handleRequest', {
info: 'Handle request',
headers: JSON.stringify(request.headers),
body: JSON.stringify(request.body)
}));
const app = new DialogflowApp({request, response});
const themes = new Themes();
const userId = app.getUser().userId;
const userIdKey = utils.encodeAsFirebaseKey(userId);
let questions = [];
let answers = [];
let followUps = [];
let gameLength = QUESTIONS_PER_GAME;
let last = false;
let middle = false;
let ssmlNoInputPrompts;
let questionPrompt;
let selectedAnswers;
let hasLastPrompt = false;
const hasScreen = app.hasSurfaceCapability(app.SurfaceCapabilities.SCREEN_OUTPUT);