chatbase 0.1.03 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ba6c32b549623e7f9db45d0de48ce88b9c04f0f8
4
- data.tar.gz: 6a05eaaa3501106d2fdf678c8d4533779d771af2
3
+ metadata.gz: cb1e68242eb852896b4470d5342203de4dda832b
4
+ data.tar.gz: f205cef1e8b32278dba509ef3efb3fbc24532152
5
5
  SHA512:
6
- metadata.gz: 958ce3922f74cf86c44276dd8468d696f6f92724dda0579b9acfcc4f9ddf174b6135849c25354b90d3a76696de829d3bad22c048e6873320184d9342212f33e0
7
- data.tar.gz: c5fcfe1dd16ec1060949be0a9c59328568a609cfb91c23a5bcdf1ee33a55efe47195d5a73afe284297a1d547c707fe66d61c4a8356a6a7a585408f61fc583178
6
+ metadata.gz: 0d03370431b3dbc850656f361f8dcb5a703288dfeb30ab8bc3c59fea63e31c3b4295e9ddcca3a72deb3e23fe1ee71fd9c4f13690c930ecfddab5d1e172c89c1e
7
+ data.tar.gz: 0c0d9b9cb2ae6c3986355963daccce6e0e9cc3749f71fba804e3058da5f3e44a8aaf3e9d3221d5966f2e70ef069b2b1ea9b1646831f030c707d67afc1112ba80
data/README.md CHANGED
@@ -21,28 +21,26 @@ bundle install chatbase
21
21
 
22
22
  # Setup
23
23
 
24
- Initialize the the gem by setting your Agent Key (agent_key) and Agent Name (agent_name).
24
+ Initialize the the gem by setting your Agent Key (agent_key).
25
25
 
26
26
  eg: config/initializers/chatbase.rb
27
27
 
28
28
  ```
29
29
  Chatbase.agent_key = 'your-agent-api-key'
30
- Chatbase.agent_name = 'your-agent-name'
31
30
  ```
32
31
 
33
32
  ## Usage
34
33
 
35
- # Supported endpoints
36
-
37
- ## Development
38
34
 
35
+ ### Generic Message API
39
36
  ```ruby
40
37
  req_params = {
41
- type: "user",
42
- platform: "our-curl-test-platform",
43
- message: "Hello Chatbase!",
38
+ platform: "ruby-test",
39
+ message: "Hello Chatbase from agent!",
44
40
  version: "1.0",
45
- user_id: "user-00"
41
+ type: "agent",
42
+ user_id: "agent-01",
43
+ time_stamp: DateTime.now.strftime('%Q'),
46
44
  }
47
45
 
48
46
  response = Chatbase::Message.new.send_message(req_params)
@@ -52,6 +50,31 @@ response = Chatbase::Message.new.send_message(req_params)
52
50
  {"message_id": "1048441442", "status": 200}
53
51
  ```
54
52
 
53
+ ### Facebook Message API
54
+ ```ruby
55
+ fb_params = {
56
+ sender: {id: '1520833104112'},
57
+ recipient: {id: '528195999812'},
58
+ timestamp: DateTime.now.strftime('%Q'),
59
+ message: {
60
+ mid: "mid.1457764197618:41d102a3e1ae206a381",
61
+ text: "hey test chatbot!"
62
+ },
63
+ chatbase_fields: {
64
+ intent: "say-hi-intent",
65
+ version: "1.01",
66
+ not_handled: false,
67
+ feedback: false
68
+ }
69
+ }
70
+
71
+ response = Chatbase::Message.new.send_fbmessage(fb_params)
72
+
73
+ => response.body
74
+
75
+ {"message_id"=>"1052280268", "status"=>200}
76
+ ```
77
+
55
78
  ## Contributing
56
79
 
57
80
  Bug reports and pull requests are welcome on GitHub at https://github.com/RTJ/chatbase. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
@@ -7,9 +7,8 @@ require 'chatbase/http_service'
7
7
 
8
8
  module Chatbase
9
9
  class << self
10
- attr_accessor :agent_key, :agent_name
10
+ attr_accessor :agent_key
11
11
  end
12
12
 
13
13
  self.agent_key ||= ENV['CHATBASE_AGENT_API_KEY']
14
- self.agent_name ||= ENV['CHATBASE_AGENT_NAME']
15
14
  end
@@ -1,25 +1,20 @@
1
1
  module Chatbase
2
2
  class HttpService
3
- attr_accessor :agent_key, :agent_name
4
-
5
- def initialize(agent_key: nil)
6
- @agent_key = agent_key || Chatbase.agent_key
7
- @agent_name = agent_name || Chatbase.agent_name
8
- end
9
3
 
10
4
  def connection
11
5
  @connection ||= begin
12
- Faraday.new(:url => 'https://chatbase.com/api/message') do |faraday|
6
+ Faraday.new(:url => 'https://chatbase.com/') do |faraday|
13
7
  faraday.response :json, :content_type => /\bjson$/
14
8
  faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
15
9
  end
16
10
  end
17
11
  end
18
12
 
19
- def request_post(data)
13
+ def request_post(url, data)
20
14
  connection.post do |req|
15
+ req.url url
21
16
  req.headers['Content-Type'] = 'application/json'
22
- req.body = {'api_key': agent_key, 'agent_name': agent_name}.merge(data).to_json
17
+ req.body = data.to_json
23
18
  end
24
19
  end
25
20
 
@@ -1,6 +1,9 @@
1
1
  module Chatbase
2
2
  class Message
3
- def initialize
3
+ attr_accessor :agent_key
4
+
5
+ def initialize(agent_key: nil)
6
+ @agent_key = agent_key || Chatbase.agent_key
4
7
  @http_service = HttpService.new
5
8
  end
6
9
 
@@ -9,7 +12,12 @@ module Chatbase
9
12
  end
10
13
 
11
14
  def send_message(request_parameters)
12
- http_service.request_post(request_parameters)
15
+ http_service.request_post("/api/message", {'api_key': @agent_key}.merge(request_parameters))
16
+ end
17
+
18
+ def send_fbmessage(request_parameters)
19
+ http_service.request_post("/api/facebook/message_received?api_key=#{@agent_key}", request_parameters)
13
20
  end
21
+
14
22
  end
15
23
  end
@@ -1,3 +1,3 @@
1
1
  module Chatbase
2
- VERSION = "0.1.03"
2
+ VERSION = "0.1.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chatbase
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.03
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eugeniu Tambur