Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Api.ai Node.js Client-Server Application Tutorial #88

Open
andreabazerla opened this issue Sep 10, 2017 · 1 comment
Open

Api.ai Node.js Client-Server Application Tutorial #88

andreabazerla opened this issue Sep 10, 2017 · 1 comment

Comments

@andreabazerla
Copy link

Hi, I'm a Node.js beginner and I don't know how to getting started with this Api.ai SDK for Node.js.

I just need a simple tutorial to create a basic Node.js client-server application, can you help me?

I've follow instructions on README.md and it works, but now I want to create a simple custom chat and then to deploy it on my remote server.

I've try to save main.js on my server, and with gulp-nodemon watch a second file that get user input; when it changes, server restarts but it doesn't work so well...

What npm/library I need to make my project?
Can I get some little help to getting started?
If you help me, I'll help you to contribute on documentation with my sample project and relative tutorial.

Thanks!

@andreabazerla andreabazerla changed the title Api.ai Node.js Client Tutorial Api.ai Node.js Client-Server Application Tutorial Sep 10, 2017
@andreabazerla
Copy link
Author

Hi, now it works but through https Node.js module.

Is it right to use https instead main.js file in README.md?

I think it's wrong because my client access token is visible on client, but it works...

const https = require('https');

const clientAccessToken = '<MY CLIENT ACCESS TOKEN>';

const callback = (data) => {
  console.log(data);
  document.getElementById('answer').innerHTML = data.result.speech;
};

document.getElementById('submit').onclick = () => {
  const question = document.getElementById('question').value;

  const options =
  {
    hostname: 'api.api.ai',
    path: '/v1/query?lang=EN&query=' + encodeURIComponent(question) + '&sessionId=1',
    method: 'GET',
    headers: {
      Authorization: 'Bearer ' + clientAccessToken,
    },
  };

  https.get(options, (res) => {
    let body = '';
    res.on('data', (data) => {
      body += data;
    });
    res.on('end', () => {
      const result = JSON.parse(body);
      callback(result);
    });
  }).on('error', (e) => {
    console.log('Error: ' + e);
  });
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant