skype_bot 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d90c1fc3afdfa2bf7dee9eeacb362f8a8be38c3d
4
- data.tar.gz: 59a0a83945a4c508568787b55f2a01fb8e6d9376
3
+ metadata.gz: 2a3954eba8aaa3cdc521406483de0600dd0060e2
4
+ data.tar.gz: 8c3fbef6e765659bbd78ecad72b0003c86ba7215
5
5
  SHA512:
6
- metadata.gz: a841e56c2c277d2de4c1eef651a4eca082f58d3cf19f30719482ddde52dd1ad9046bb1919586206b1961cad16c6b6a62d90f2cdea8fa5b22b9e9a728f443a48f
7
- data.tar.gz: 2de28dae426d6b060408be17c24feab53601233150a4c928dd561f19d4ce83130f3b9a8cbe1f036b288961f6b02e0af9b916f092ddcc33193664a306e0e0bfc7
6
+ metadata.gz: a3c8959f866ac3432266b1bb0768aa626e08e960039e63aaff35b8e1956cf14c58890495afd3c09211ca9ee0dc811a92c41253b5db2c5babbe6b5ea0089dd15e
7
+ data.tar.gz: ba37f46699b72aa4d5dc4db293a13f3fc739d81fa0464e82b953313030584e4fc6d18335360b466641cad5a615eab4d6e857d0bd5a1357e068b7afa8bf326d82
@@ -1,5 +1,6 @@
1
1
  require 'typhoeus'
2
2
 
3
+ require 'skype_bot/card'
3
4
  require 'skype_bot/activity'
4
5
  require 'skype_bot/auth'
5
6
  require 'skype_bot/config'
@@ -14,7 +15,11 @@ module SkypeBot
14
15
  end
15
16
 
16
17
  def message(uid, content)
17
- Activity.text_message(uid, content)
18
+ Activity.new(uid).sent(content)
19
+ end
20
+
21
+ def card(format, uid, payload)
22
+ Card.call(format, uid, payload)
18
23
  end
19
24
 
20
25
  def parser(data)
@@ -1,25 +1,28 @@
1
1
  module SkypeBot
2
- module Activity
3
- extend self
4
-
2
+ class Activity
5
3
  CONVERSATION_URL = 'https://skype.botframework.com/v3/conversations'
6
4
 
7
- def text_message(uid, content)
5
+ attr_accessor :uid
6
+
7
+ def initialize(uid)
8
+ @uid = uid
9
+ end
10
+
11
+ def sent(content)
8
12
  token = Auth.get_token
9
- body = payload(uid, content).to_json
13
+ body = payload(content).to_json
10
14
  headers = { Authorization: "Bearer #{token}", 'Content-Type': 'application/json' }
11
- url = activity_url(uid)
12
15
 
13
- Typhoeus.post(url, body: body, headers: headers)
16
+ Typhoeus.post(activity_url, body: body, headers: headers)
14
17
  end
15
18
 
16
19
  private
17
20
 
18
- def activity_url(uid)
21
+ def activity_url
19
22
  "#{CONVERSATION_URL}/#{uid}/activities"
20
23
  end
21
24
 
22
- def payload(uid, content)
25
+ def payload(content)
23
26
  {
24
27
  type: 'message',
25
28
  agent: 'botbuilder',
@@ -0,0 +1,14 @@
1
+ require 'skype_bot/cards/base'
2
+ require 'skype_bot/cards/hero'
3
+ require 'skype_bot/cards/carousel'
4
+ require 'skype_bot/cards/sign_in'
5
+
6
+ module SkypeBot
7
+ module Card
8
+ extend self
9
+
10
+ def call(format, uid, payload)
11
+ Cards.const_get(format.to_s.classify).new(uid).sent(payload)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,43 @@
1
+ module SkypeBot
2
+ module Cards
3
+ class Base
4
+ CONVERSATION_URL = 'https://skype.botframework.com/v3/conversations'
5
+
6
+ attr_accessor :uid
7
+
8
+ def initialize(uid)
9
+ @uid = uid
10
+ end
11
+
12
+ def sent(data)
13
+ token = Auth.get_token
14
+ attachments = build_attachments(data)
15
+ body = payload(attachments).to_json
16
+ headers = { Authorization: "Bearer #{token}", 'Content-Type': 'application/json' }
17
+
18
+ Typhoeus.post(activity_url, body: body, headers: headers)
19
+ end
20
+
21
+ def activity_url
22
+ "#{CONVERSATION_URL}/#{uid}/activities"
23
+ end
24
+
25
+ def payload(attachments)
26
+ {
27
+ type: 'message',
28
+ agent: 'botbuilder',
29
+ source: 'skype',
30
+ address: {
31
+ channelId: 'skype',
32
+ user: { id: uid },
33
+ bot: { id: "#{Config.skype_number}:#{Config.app_id}" },
34
+ serviceUrl: 'https://skype.botframework.com',
35
+ useAuth: true
36
+ },
37
+ textFormat: 'xml',
38
+ attachments: attachments
39
+ }
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,28 @@
1
+ module SkypeBot
2
+ module Cards
3
+ class Carousel < Base
4
+
5
+ def payload(attachments)
6
+ {
7
+ type: 'message',
8
+ agent: 'botbuilder',
9
+ source: 'skype',
10
+ address: {
11
+ channelId: 'skype',
12
+ user: { id: uid },
13
+ bot: { id: "#{Config.skype_number}:#{Config.app_id}" },
14
+ serviceUrl: 'https://skype.botframework.com',
15
+ useAuth: true
16
+ },
17
+ textFormat: 'xml',
18
+ attachmentLayout: 'carousel',
19
+ attachments: attachments
20
+ }
21
+ end
22
+
23
+ def build_attachments(attachments)
24
+ attachments.map { |attachment| { contentType: "application/vnd.microsoft.card.hero", content: attachment } }
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,15 @@
1
+ module SkypeBot
2
+ module Cards
3
+ class Hero < Base
4
+
5
+ def build_attachments(attachment)
6
+ [{
7
+ contentType: "application/vnd.microsoft.card.hero",
8
+ content: attachment
9
+ }]
10
+ end
11
+ end
12
+ end
13
+ end
14
+
15
+ # {:title=>"Hero Card", :subtitle=>"Space Needle", :text=> "The <b>Space Needle</b> is an observation tower in Seattle, Washington, a landmark of the Pacific Northwest, and an icon of Seattle.", :images=> [{:url=> "https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/Seattlenighttimequeenanne.jpg/320px-Seattlenighttimequeenanne.jpg"}], :buttons=> [{:type=>"openURL", :value=>"https://www.ring.md", :title=>"Current Weather"}]}
@@ -0,0 +1,20 @@
1
+ module SkypeBot
2
+ module Cards
3
+ class SignIn < Base
4
+
5
+ def build_attachments(data)
6
+ [{
7
+ contentType: 'application/vnd.microsoft.card.signin',
8
+ content: {
9
+ text: data[:title],
10
+ buttons: [{
11
+ type: 'signin',
12
+ title: data[:title],
13
+ value: data[:url]
14
+ }]
15
+ }
16
+ }]
17
+ end
18
+ end
19
+ end
20
+ end
@@ -1,3 +1,3 @@
1
1
  module SkypeBot
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: skype_bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - MQuy
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-07-23 00:00:00.000000000 Z
11
+ date: 2016-07-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -98,8 +98,12 @@ files:
98
98
  - bin/setup
99
99
  - lib/skype_bot.rb
100
100
  - lib/skype_bot/activity.rb
101
- - lib/skype_bot/attachment.rb
102
101
  - lib/skype_bot/auth.rb
102
+ - lib/skype_bot/card.rb
103
+ - lib/skype_bot/cards/base.rb
104
+ - lib/skype_bot/cards/carousel.rb
105
+ - lib/skype_bot/cards/hero.rb
106
+ - lib/skype_bot/cards/sign_in.rb
103
107
  - lib/skype_bot/config.rb
104
108
  - lib/skype_bot/parser.rb
105
109
  - lib/skype_bot/version.rb
File without changes