aboie 0.9.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f3c0bb2b00399a19f35ce6bc0050edb6b8cdbe35
4
+ data.tar.gz: 43fb249ac107f923c68e53386ad608ca2007c8d6
5
+ SHA512:
6
+ metadata.gz: a0de2cee5e89729cc0db11035f01815616fe2935be244f950c9f13a5aee736439469cf7804b006daaee25e751aed1c98c54c3dcdb7c67b13b05553149dac2189
7
+ data.tar.gz: a11ce231aad7b0c3a4c96897436e1849f5ffe8a5370720251f037448f442cd388cf7ee7f0c805c36c01f77dacdd033d8dca12afa198e26aee2863c7ed2e6a40c
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in aboie.gemspec
4
+ gemspec
@@ -0,0 +1,80 @@
1
+ # Aboie
2
+
3
+
4
+ Aboie is a Framework for Facebook Messanger bots built with Ruby.
5
+
6
+ * Parses incomming message json into the commonly required parts (Sender) and (Message)
7
+ * Easily send text message responses via the Facebook Messanger API (Destination) & (Message)
8
+ * Support for Rich Media messages. (TODO)
9
+
10
+
11
+ ### Why Aboie
12
+
13
+ Aboie is a french command when training dogs that means Speak or Bark.
14
+
15
+ ## Getting Started:
16
+
17
+ This assumes you have read the facebook docs [https://developers.facebook.com/docs/messenger-platform](https://developers.facebook.com/docs/messenger-platform), and have created an api key.
18
+
19
+ ### Installation:
20
+
21
+ Add
22
+
23
+ `gem 'aboie`
24
+
25
+ it
26
+
27
+ ### Configuration:
28
+
29
+ Create an initializer with the following
30
+
31
+ ```
32
+ Aboie.configure do |config|
33
+ config.api_key = "messanger_api_key"
34
+ end
35
+ ```
36
+
37
+
38
+ ### Parsing webhooks
39
+
40
+ Follow the instructions to setup an inbound webhook for the Messanger Api.
41
+ Aboie can help you parse through the large object and make sense of it.
42
+
43
+ ```
44
+ module Webhooks
45
+ class FacebooksController < ActionController::Base
46
+ include Webhooks::Facebook::Verifiable
47
+
48
+ def create
49
+ messages = Aboie.parse_payload(params)
50
+ message = messages.first
51
+ query = message[:text]
52
+ response = Chat::Brain.ask(query)
53
+ Aboie.send_text(message[:sender], response)
54
+ render nothing: true, status: :ok
55
+ end
56
+
57
+ end
58
+ end
59
+
60
+ ```
61
+
62
+ Aboie.parse_payload(params) will parse the array of potential messages, into a simple array containing a hash with `{text: "Message", sender: "SenderId"}` this data can be used to formulate a response and respond to the proper sender id, using Aboie's easy message sending capabilities via `Aboie.send_text` which takes a `(sender_id, message)` as outlined in the example.
63
+
64
+
65
+
66
+
67
+ ## Questions? Issues?
68
+
69
+ For issues, please submit a Github issue with steps on how to reproduce the problem.
70
+
71
+
72
+ ## Contributions
73
+
74
+ Contributions are welcome. Tests are encouraged.
75
+
76
+ To run tests / ensure your changes have not caused any regressions:
77
+
78
+ ```
79
+ rspec
80
+ ```
File without changes
@@ -0,0 +1,38 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'aboie/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "aboie"
8
+ spec.version = Aboie::VERSION
9
+ spec.authors = ["Justin McNally"]
10
+ spec.email = ["justin.cole.mcnally@gmail.com"]
11
+
12
+ spec.summary = %q{Aboie API}
13
+ spec.description = %q{A gem for facebook messanger api}
14
+ spec.homepage = "http://www.github.com/j-mcnally"
15
+
16
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
17
+ # delete this section to allow pushing this gem to any host.
18
+ # if spec.respond_to?(:metadata)
19
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
20
+ # else
21
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
22
+ # end
23
+
24
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_dependency "rest-client", "~> 2.0.0.rc2"
30
+ spec.add_dependency "oj", "2.13.1"
31
+
32
+
33
+ spec.add_development_dependency "webmock", "1.23.0"
34
+ spec.add_development_dependency "bundler", "~> 1.10"
35
+ spec.add_development_dependency "rake", "~> 10.0"
36
+ spec.add_development_dependency "rspec"
37
+ spec.add_development_dependency "awesome_print", '1.6.1'
38
+ end
@@ -0,0 +1,22 @@
1
+ require 'rest-client'
2
+ require 'oj'
3
+
4
+ require 'aboie/version'
5
+ require 'aboie/configuration/base'
6
+ require 'aboie/client'
7
+ require 'aboie/errors'
8
+ require 'aboie/parser'
9
+
10
+ module Aboie
11
+ extend Configuration::Base
12
+ extend Parser
13
+
14
+ def self.default_client
15
+ @@client ||= Aboie::Client.new
16
+ end
17
+
18
+ def self.method_missing(name, *args)
19
+ self.default_client.send(name, *args)
20
+ end
21
+
22
+ end
@@ -0,0 +1,28 @@
1
+ module Aboie
2
+ class Client
3
+ attr_accessor :api_key
4
+ def initialize(api_key=nil)
5
+ self.api_key = api_key || Aboie.configuration.api_key
6
+ end
7
+
8
+ def send_text(who, msg)
9
+
10
+ payload = {
11
+ recipient: {id: who},
12
+ message: {text: msg}
13
+ }
14
+
15
+ begin
16
+ RestClient.post("https://graph.facebook.com/v2.6/me/messages?access_token=#{self.api_key}",
17
+ payload.to_json,
18
+ {accept: :json, content_type: :json}
19
+ )
20
+ rescue StandardError => e
21
+ puts e.response.inspect
22
+ puts e.response.body
23
+ raise e
24
+ end
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,20 @@
1
+ module Aboie
2
+ module Configuration
3
+ module Base
4
+ def reset
5
+ @@configuration = OpenStruct.new
6
+ end
7
+ def configure(&block)
8
+ yield configuration
9
+ end
10
+
11
+ def configuration
12
+ @@configuration
13
+ end
14
+
15
+ def self.extended(base)
16
+ base.reset
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1 @@
1
+ require 'aboie/errors/authentication_error'
@@ -0,0 +1,3 @@
1
+ module Aboie
2
+ class AuthenticationError < StandardError; end
3
+ end
@@ -0,0 +1,15 @@
1
+ module Aboie
2
+ module Parser
3
+ def parse_payload(payload)
4
+ payload = Oj.load(payload) if payload.is_a?(String)
5
+ messages = []
6
+ payload["entry"].each do |entry|
7
+ next if entry["messaging"].nil?
8
+ entry["messaging"].each do |msg|
9
+ messages.push({sender: msg["sender"]["id"], text: msg["message"]["text"]})
10
+ end
11
+ end
12
+ messages
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module Aboie
2
+ VERSION = "0.9.0"
3
+ end
metadata ADDED
@@ -0,0 +1,155 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aboie
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.0
5
+ platform: ruby
6
+ authors:
7
+ - Justin McNally
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-04-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.0.0.rc2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.0.0.rc2
27
+ - !ruby/object:Gem::Dependency
28
+ name: oj
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 2.13.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 2.13.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: webmock
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 1.23.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 1.23.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.10'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.10'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: awesome_print
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '='
102
+ - !ruby/object:Gem::Version
103
+ version: 1.6.1
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '='
109
+ - !ruby/object:Gem::Version
110
+ version: 1.6.1
111
+ description: A gem for facebook messanger api
112
+ email:
113
+ - justin.cole.mcnally@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rspec"
120
+ - Gemfile
121
+ - README.md
122
+ - Rakefile
123
+ - aboie.gemspec
124
+ - lib/aboie.rb
125
+ - lib/aboie/client.rb
126
+ - lib/aboie/configuration/base.rb
127
+ - lib/aboie/errors.rb
128
+ - lib/aboie/errors/authentication_error.rb
129
+ - lib/aboie/parser.rb
130
+ - lib/aboie/version.rb
131
+ homepage: http://www.github.com/j-mcnally
132
+ licenses: []
133
+ metadata: {}
134
+ post_install_message:
135
+ rdoc_options: []
136
+ require_paths:
137
+ - lib
138
+ required_ruby_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ required_rubygems_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ requirements: []
149
+ rubyforge_project:
150
+ rubygems_version: 2.4.5
151
+ signing_key:
152
+ specification_version: 4
153
+ summary: Aboie API
154
+ test_files: []
155
+ has_rdoc: