How to use the dialogflow.SessionsClient function in dialogflow

To help you get started, we’ve selected a few dialogflow examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github googleapis / nodejs-dialogflow / samples / quickstart.js View on Github external
async function runSample(projectId = 'your-project-id') {
  // A unique identifier for the given session
  const sessionId = uuid.v4();

  // Create a new session
  const sessionClient = new dialogflow.SessionsClient();
  const sessionPath = sessionClient.sessionPath(projectId, sessionId);

  // The text query request.
  const request = {
    session: sessionPath,
    queryInput: {
      text: {
        // The query to send to the dialogflow agent
        text: 'hello',
        // The language used by the client (en-US)
        languageCode: 'en-US',
      },
    },
  };

  // Send request and log result
github googleapis / nodejs-dialogflow / samples / detect.js View on Github external
projectId,
  sessionId,
  filename,
  encoding,
  sampleRateHertz,
  languageCode
) {
  // [START dialogflow_detect_intent_audio]
  const fs = require('fs');
  const util = require('util');
  const {struct} = require('pb-util');
  // Imports the Dialogflow library
  const dialogflow = require('dialogflow');

  // Instantiates a session client
  const sessionClient = new dialogflow.SessionsClient();

  // The path to identify the agent that owns the created intent.
  const sessionPath = sessionClient.sessionPath(projectId, sessionId);

  // Read the content of the audio file and send it as part of the request.
  const readFile = util.promisify(fs.readFile);
  const inputAudio = await readFile(filename);
  const request = {
    session: sessionPath,
    queryInput: {
      audioConfig: {
        audioEncoding: encoding,
        sampleRateHertz: sampleRateHertz,
        languageCode: languageCode,
      },
    },
github shekit / peeqo / electron / app / js / intent-engines / dialogflow.js View on Github external
function setup(){
	// DIALOGFLOW

	//create unique id for new dialogflow session
	const sessionId = uuid.v4()

	//create a dialogflow session
	const sessionClient = new dialogflow.SessionsClient({
		projectId: config.speech.projectId,
		keyFilename: path.join(process.cwd(), 'app', 'config', config.speech.dialogflowKey)
	})

	const sessionPath = sessionClient.sessionPath(config.speech.projectId, sessionId)

	// the dialogflow request
	const dialogflowRequest = {
		session: sessionPath,
		queryParams: {
			session: sessionClient.sessionPath(config.speech.projectId, sessionId)
		},
		queryInput:{
			audioConfig:{
				audioEncoding: "AUDIO_ENCODING_LINEAR_16",
				sampleRateHertz: 16000,
github googleapis / nodejs-dialogflow / samples / detect.js View on Github external
encoding,
  sampleRateHertz,
  languageCode
) {
  // [START dialogflow_detect_intent_streaming]
  const fs = require('fs');
  const util = require('util');
  const {Transform, pipeline} = require('stream');
  const {struct} = require('pb-util');

  const pump = util.promisify(pipeline);
  // Imports the Dialogflow library
  const dialogflow = require('dialogflow');

  // Instantiates a session client
  const sessionClient = new dialogflow.SessionsClient();

  // The path to the local file on which to perform speech recognition, e.g.
  // /path/to/audio.raw const filename = '/path/to/audio.raw';

  // The encoding of the audio file, e.g. 'AUDIO_ENCODING_LINEAR_16'
  // const encoding = 'AUDIO_ENCODING_LINEAR_16';

  // The sample rate of the audio file in hertz, e.g. 16000
  // const sampleRateHertz = 16000;

  // The BCP-47 language code to use, e.g. 'en-US'
  // const languageCode = 'en-US';
  const sessionPath = sessionClient.sessionPath(projectId, sessionId);

  const initialStreamRequest = {
    session: sessionPath,
github AdaptiveConsulting / ReactiveTraderCloud / src / server / Adaptive.ReactiveTrader.Server.Bot / src / nlp-services.ts View on Github external
interface DFResultWithOriginalMessage {
  originalMessage: Message
  intentResponse: DialogueFlow.DetectIntentResponse
}

export interface IntentNumberParameter {
  numberValue: number
}

export interface IntentStringParameter {
  stringValue: string
}

const projectId = 'adaptive-trader'
const sessionId = uuid.v4()
const sessionClient = new DialogueFlow.SessionsClient()
const sessionPath = sessionClient.sessionPath(projectId, sessionId)

export function createNlpStream(symphony: SymphonyClient) {
  const createNLPRequest = (text: string) => ({
    session: sessionPath,
    queryInput: {
      text: {
        text,
        languageCode: 'en-US',
      },
    },
  })

  const intentsFromDF$: Observable = symphony
    .dataEvents$()
    .pipe(
github CampbellCrowley / SpikeyBot-Discord / src / chatbot.js View on Github external
self.Discord.Permissions.FLAGS.MANAGE_GUILD |
                  self.Discord.Permissions.FLAGS.BAN_MEMBERS,
            })));

    self.client.on('message', onMessage);

    selfMentionRegex = new RegExp(`\\s*<@!?${self.client.user.id}>\\s*`);

    if (self.bot.getBotName()) {
      process.env.GOOGLE_APPLICATION_CREDENTIALS =
          './gApiCredentials-' + self.bot.getBotName() + '.json';
    } else {
      process.env.GOOGLE_APPLICATION_CREDENTIALS = './gApiCredentials.json';
    }

    sessionClient = new dialogflow.SessionsClient();

    self.client.guilds.forEach(function(g) {
      fs.readFile(
          self.common.guildSaveDir + g.id + '/chatbot-config.json',
          function(err, file) {
            if (err) return;
            let parsed;
            try {
              parsed = JSON.parse(file);
            } catch (e) {
              return;
            }
            disabledChatBot[g.id] = parsed.disabledChatBot || false;
          });
    });
  };
github jschnurr / botkit-middleware-dialogflow / src / api.js View on Github external
constructor(config) {
    this.config = config;
    const opts = _.pick(config, [
      'credentials',
      'keyFilename',
      'projectId',
      'email',
      'port',
      'promise',
      'servicePath',
    ]);

    this.projectId = opts.projectId;

    this.app = new dialogflow.SessionsClient(opts);
  }
github KovDimaY / MERN-ChatBot / server / services / df-service.js View on Github external
const dialogflow = require('dialogflow');
const structjson = require('../utils/structjson');
const {
  googleProjectID, dialogFlowSessionID, dialogFlowSessionLanguageCode,
  googleClientEmail, googlePrivateKey,
} = require('../config/keys');

const { Feedback } = require('../models/Feedback');

const projectID = googleProjectID;
const credentials = {
  client_email: googleClientEmail,
  private_key: googlePrivateKey,
};

const sessionClient = new dialogflow.SessionsClient({ projectID, credentials });

module.exports = {
  textQuery: async (query, userID, params = {}) => {
    const self = module.exports;
    const sessionPath = sessionClient.sessionPath(googleProjectID, dialogFlowSessionID + userID);
    const request = {
      session: sessionPath,
      queryInput: {
        text: {
          text: query,
          languageCode: dialogFlowSessionLanguageCode,
        },
      },
      queryParams: {
        payload: {
          data: params,
github fireship-io / 202-chatbot-dialogflow / functions / index.js View on Github external
cors(request, response, async () => {
    const { queryInput, sessionId } = request.body;


    const sessionClient = new SessionsClient({ credentials: serviceAccount });
    const session = sessionClient.sessionPath('fireship-lessons', sessionId);


    const responses = await sessionClient.detectIntent({ session, queryInput});

    const result = responses[0].queryResult;

    response.send(result);
  });
});
github gfaraj / super-bot / src / plugins / natural.js View on Github external
bot.command('natural', async (bot, message) => {
        if (!sessionClient) {
            sessionClient = new dialogflow.SessionsClient();
        }

        const sessionPath = sessionClient.sessionPath(process.env.GOOGLE_PROJECT_ID, message.chat.id);
        const request = {
            session: sessionPath,
            queryInput: {
                text: {
                    text: message.text,
                    languageCode: 'en-US',
                },
            },
        };
        const responses = await sessionClient.detectIntent(request);
        if (responses.length > 0) {
            const result = responses[0].queryResult;        
            bot.respond(result.fulfillmentText);