- APIs
- Argument vs Parameter
- Asynchronous JavaScript
- Authentication and Authorization
- Banking APIs
- Chatbot Resources
- Dialogflow
- ES6
- Express
- Git
- Heroku
- joi
- Links
- mongoDB
- CLI
- Implementation
- ngrok
- NPM Packages
- Object Oriented Programming
- PostgreSQL
- React
- RESTful
- Sendgrid
- myTeachable
- Cassandra vs MongoDB
- OpenWeatherMap API
- API.ai
- Travel APIs Providers
- What APIs are there for finding flights?
- Commission Junction
- OpenWeather API - 8202bf8ac17a5affa77cb6942abb73a5
- APIs for flight fare search
Waiting for actions to finish is implicit in the synchronous model, while it is explicit, under our control, in the asynchronous one.
var myArray = new Array();document.getElementById("id").onClick- onClick property returns the click event handler code on the current element
var myArray = new Array()=function() {
document.getElementById('first dev').innerHTML = myArray[1];
}- Eloquent Javascript
- Writing neat asynchronous Node JS code with Promises & Async/Await
- Async/await
.thenmethod - registers a callback function to be called when the promise resolves and produces a value. You can add multiple callbacks to a single promise, and they will be called, even if you add them after the promise has already resolved (finished)..thenmethod returns another promise, which resolves to the value that the handler function returns or, if that returns a promise, waits for the promise and then resolves its result.- To create a promise, you can use promise as a constructor.
- Construtor - method for creating and initializing an object created within a class.
Promise- based interface for thereadStoragefunction:
function storage(nest, name) {
return new Promise(resolve => {
nest.readStorage(name, result => resolve(result));
});
}
storage(bigOak, "enemies")
.then(value => console.log('Got', value));Main advantage of Promises is that they simplify use of callback functions.
Instead of having to pass around callbacks, promise-based functions look similar to regular ones: they take input as arguments and return their outputs.
Async code is used to load data into tables, make requests to the server, load DOM elements on priority, write non-blocking code on Node.
We create a promise in our Node.js program using the 'new' constructor.
var myPromise = new Promise (function(resolve, reject)){}let- allows you to declare variables that are limited in scope to the block, statement, or expression on which it is used.letbindings are created at the top of the (block) scope containing the declaration => this ishoisting.varkeyword - defines a variable globally, or locally to entire function regardless of block scope.
There are three patterns to deal with asynchronous code:
- Callbacks - a function to call when a result of an asynchronous operation is ready. Callbacks are used to signal completion of a task.
- Promises - object that can hold results of an asynchronous operation. It can be in 3 states: Pending, Fulfilled and Rejected. Initially, it is an a pending state. If the operation is completed successfully it is resolved or fulfilled. If the state of the promise fails, it will go from pending to rejected. Every
promiseobject has two method. If you have an async function that returns a callback, modify it to return a promise. A promise is an asynchronous action that may complete at some point and produce a value. It is able to notify anyone who is interested when its value is available. To get the result of a promise, you can use its then method. This registers a callback function to be called when the promise resolves and produces a value. You can add multiple callbacks to a single promise, and they will be called, even if you add them after the promise has already resolved (finished). The main advantage of promises—they simplify the use of asynchronous functions. - Async/await
- Register: POST /api/users {name, email, password}
email: {
type: String,
unique: true
}- Login: POST /api/logins
- Callbacks are used to signal completion of a task.
setTimeoutfunction waits a given number of milliseconds and then calls a function"
setTimeout(() => console.log('Vuk'), 2000);import {bigOak} from "./crow-tech"
bigOak.readStorage("food cache", cache = > {
let firstCache = cache[0];
bigOak.readStorage(firstCache, info => {
console.log(info);
});
});.then- method registers a callback function to be called when the promise resolves and produces a value. You can add multiple callbacks to a single promise, and they will be called, even if you add them after the promise has already resolved (finished)..then- method returns another promise, which resolves to value that the handler function returns or, if that returns a promise, waits for that promise then resolves its result.
It can be in 3 states: Pending, Fulfilled and Rejected. Initially, it is an a pending state. If the operation is completed successfully it is resolved or fulfilled. If the state of the promise fails, it will go from pending to rejected. Every promise object has two method.
To create a promise, you can use Promise as a constructor.
constructor - method for creating and initializing an object created within a class.
If you have an async function that returns a callback, modify it to return a promise.
A promise is an asynchronous action that may complete at some point and produce a value. It is able to notify anyone who is interested when its value is available. To get the result of a promise, you can use its then method. This registers a callback function to be called when the promise resolves and produces a value. You can add multiple callbacks to a single promise, and they will be called, even if you add them after the promise has already resolved (finished). The main advantage of promises—they simplify the use of asynchronous functions.
The easiest way to create a promise is by calling Promise.resolve. To get the result of a promise, you can use its then method.
let fifteen = Promise.resolve(15);
fifteen.then(value => console.log( 'Got ${value} ')):- Parameter is a variable in a method definition. When a method is called, the arguments are the data you pass into the method's parameters.
- Parameter is a variable in the declaration of a function. Argument is the actual value of this variable that gets passed to function.
- A parameter is a variable defined by a method that receives a value when the method is called.
- An argument is a value that is passed to a method when it is invoked.
- parameters are the name within the function definition.
- Arguments are the values passed in when the function is called.
- Parameters don’t change when the program is running
- Arguments are probably going to be different every time the function is called.
- Bootpages
- Botlist
- Dashbot
- Entities Overview
- Chatbot Comparison – Facebook, Microsoft, Amazon, and Google
- OpenWeatherMap
- Dialogflow
- Dialogflow is a natural language processor used to understand what our visitors want from the bot. Components to use: agents, intents, parameters, prebuilt agents, slotfilling, etc.
- React
- NodeJS
- mongoDB
- ExpressJS
- git
- Heroku
- Nodemon - local development server
- rich messages like cards and quick replies.
- setup React, configure local servers, create a proxy for communicating with backend.
- Slotfilling - the task is to complete all known information about a given query entity.
- Entity Linking - Spanning multiple documents and linking mentions to concrete entities (when possible), rather than simply clustering them.
export GOOGLE_APPLICATION_CREDENTIALS=/path-to-keys/key-file.jsonEvery time you restart the computer run this command to set up the environment variable. It you see the authentication error it is because the environment variable is reset.export GOOGLE_APPLICATION_CREDENTIALS=/Users/vukdukic/Apps/Chatbot/crowdart-8e66f-0062b215343e.json- Dialogflow: Node.js Client
- Rich messages
- Dialogflow Console
- Create fulfillment using webhook
- Setting up authentication
- System Entities
- Make your agent multilingual
- Google Project FAQ
- Method: projects.agent.sessions.detectIntent
- Follow-up intent expressions
- Sharing
- Share your agent
- Setting up authentication
- Method: projects.agent.sessions.detectIntent
use strict; Defines that JavaScript code should be executed in "strict mode", a literal expression. With strict mode, you can not, for example, use undeclared variables.
- With object destructuring, when declaring a variable or constant use {} and add the property of the target object.
- Node.js - operates on a single thread event loop, using non-blocking I/O calls, allowing it to support tens of thousands of concurrent connections without incurring the cost of thread context switching.
Bulding webservices on top of Node.js.
export PORT=5000- http://localhost:5000/api/post/2018/1?sortby=name
app.use(express.json)- when we callexpress.jsonmethod, the method returns a piece of middleware and then we call theapp.useto use the middleware in the request processing timeline.- When the server creates a new object and/or resource it should write that in the body of the response.
- Facebook Messenger Generic Template
- Messenger Platform
- Button Template
- EAADnk6ZBTzAQBALZBN7TAfAqlw1WChZAjs86ZAgZBuZCpPcm3aQdxaw5wjXThuFRjaQzGmIjU7QAldii1B8ZCCG975RMhnXIRrgZAaRZBGRZAHCmLZAYdQoECvgTJQ1okrayZBhpJsqZCZCKsIryT8DAUKODnUYBeKmLnTPQ0yl3IzMWcJPAZDZD
- Webhook
- Callback URL: https://chatbot-facebook1.herokuapp.com/webhook/
- Verify Token: my_chatbot_password
- Subscription fields: messages, messaging postbacks
- Messenger Settings
- chatbot-facebook-v2-final
- Reference Documentation
- Integration Components
- Message Templates
- Messenger Platform
Facebook will make a request to that URL from their servers to deliver the updates – so of course it has to be publicly reachable over the internet, which a localhost address obviously isn’t.
Facebook will send a request to that URL if any data for the object and fields that you subscribed for changes. And what the data structure looks like, is described in the docs. For page fields it returns the new content directly; for user fields it will only tell you which fields have changed, so that you can then make a request for that data.
You can only get real-time updates for pages that you have admin access to. And the Public Feed API is not deprecated; but access to it is limited to a small set of Facebook partners. You can not apply to become one – if you absolutely need this kind of data, then you’ll have to contact one of those partners and have them develop a solution for you.
- [https://dont-be-afraid-to-commit.readthedocs.io/en/latest/git/commandlinegit.html](Git on the commandline)
- Actions on Google
- Google Cloud AI Products
- Google Maps Platform
- Setting Up Authentication for Server to Server Production Applications
- Service Accounts
- Understanding Service Accounts
- gcloud auth application-default print-access-token
- gcloud auth activate-service-account
- Google Cloud SDK Documentation
- ./google-cloud-sdk/bin/gcloud init
- gcloud init --skip-diagnostics
- ./google-cloud-sdk/bin/gcloud auth activate-service-account
- ./google-cloud-sdk/bin/gcloud auth print-access-token
- export REACT_APP_DIALOGFLOW_CLIENT_KEY=
- export REACT_APP_DIALOGFLOW_CLIENT_ID=
- export REACT_APP_DF_SESSION_ID=
- echo $REACT_APP_DIALOGFLOW_CLIENT_KEY
joi allows you to create blueprints or schemas for JavaScript objects (an object that stores information) to ensure validation of key information.
- Live Agent Developer Guide
- How Are Apps Authenticated with the Web Server OAuth Authentication Flow?
- Web Services Architecture
- Swagger Editor Github
- Configure your Node.js Applications
- Chatbot Tech Stack
sudo mkdir -p /data/dbsudo chown -Rid -un/data/dbmongod- mongo daemon (computer program that runs as a background process)
mongoose.connect('mongodb://localhost/databaseName');//connection string for local server - it prod it should come from the config filemongoose.connect(config.mongoURI, { useNewUrlParser: true });connectmethod returns a promise
ngrok allows you to expose a web server running on your local machine to the internet.
- ngrok dashboard With the fremium version, each time we run a ngrok command a new address will be created
- ngrok documentation
- INSPECT
- sudo cp ngrok /usr/local/bin
- /usr/local/bin/ngrok authtoken tokenxxxxxx
- /usr/local/bin/ngrok http 5000
- /usr/local/bin/ngrok http -subdomain=xxxx 5000
- Node.js Request Module Tutorial
- An Update on ES6 Modules in Node.js
- Node.js operatates on a single thread event loop, using non-blocking I/O calls, allowing it to support tens of thousand concurrent connections without incurring the cost of thread context switching.
- nodemon
- [Concurrently]
- http-proxy-middleware
- npm install axios --save
- uuid - npm i uuid --save
npm i universal-cookie --save
- joi-password-complexity
request- npm package removes the boilerplate code of inbuilt http package.npm install concurrently --save-dev- Run multiple commands concurrently.
Four pillars of object oriented programming:
- Encapsulation - isolate impact of changes (reduce complexity)
- Abstraction - isolate impact of changes
- Inheritance - eliminate redundant code
- Polymorphism - refactor switch/case statements
- npm install --save react-router-dom
- HTML DOM scrollIntoView Method
- Refs and the DOM
- Conditional Rendering
- State and Lifecycle
componentDidUpdate- method is called after the component is re-rendered.- With Refs- to access DOM nodes of React elements created when rendering components.
- javascript functions
- states
- lifecycle hooks (componentWillMount, componentDidMount)
- extra methods
When you have some piece of application state that needs to be mapped to multiple components
- Generate
unique idin React frontend - Set the id to cookie
- Send this id to API endpoint in backend app
- Construct a session from global session and unique id
- Make a call to Dialogflow with new session
- header
- image
- description
- link
- price
- callback function is: (req, res) => {}
- use
letidentifier if you want to reset the variable later app.use(express.json);- when we callexpress.jsonmethod, the method returns a piece of middleware, and then we callapp.useto use the middleware in the request processing timeline.- When the server creates a new object and/or resource, it should write that in the body of the response