Wednesday 2 August 2017

Rails 5.1 with webpack and api-ai SDK

Here we are going to see how to use webpacker with rails application and adding one javascript SDK with rails application.

Webpack

Here webpack takes modules with dependencies and generates static representing those modules.

reference link

https://webpack.github.io/docs/what-is-webpack.html



Let we start with step by step Processes


a.Create new rails repo with webpacker
rails new myapp --webpack

b. File called package.json is created inside the myapp(rails repo) with content


{
  "name": "chat_bot",
  "private": true,
  "dependencies": {}
}

c. Add required javascript lib inside the  package.json under 
dependencies. 
here we are adding the api.ai SDK into package.json

ex: 

{
  "name": "chat_bot",
  "private": true,
  "dependencies": {
    "api-ai-javascript" : "~> 2.0.0-beta.21"}

}

d. Once this added please run npm install at myapp(rails repo) 
directory level. 

e. Make sure to require "api-ai-javascript"  at application.js or 
where ever you required.

f. Now javascript web SDK for API.ai is available throughout the project


Note : If you are using less then the rails5.1 then the way of 
adding the SDK will be different. Please look into reference link. 

Reference link

https://github.com/rails/webpacker

https://github.com/api-ai/apiai-javascript-client