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 +4 -4
- data/README.md +32 -9
- data/lib/chatbase.rb +1 -2
- data/lib/chatbase/http_service.rb +4 -9
- data/lib/chatbase/message.rb +10 -2
- data/lib/chatbase/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cb1e68242eb852896b4470d5342203de4dda832b
|
|
4
|
+
data.tar.gz: f205cef1e8b32278dba509ef3efb3fbc24532152
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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)
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
message: "Hello Chatbase!",
|
|
38
|
+
platform: "ruby-test",
|
|
39
|
+
message: "Hello Chatbase from agent!",
|
|
44
40
|
version: "1.0",
|
|
45
|
-
|
|
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.
|
data/lib/chatbase.rb
CHANGED
|
@@ -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/
|
|
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 =
|
|
17
|
+
req.body = data.to_json
|
|
23
18
|
end
|
|
24
19
|
end
|
|
25
20
|
|
data/lib/chatbase/message.rb
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
module Chatbase
|
|
2
2
|
class Message
|
|
3
|
-
|
|
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
|
data/lib/chatbase/version.rb
CHANGED