skype_bot 0.0.5 → 0.0.6

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: 2a3954eba8aaa3cdc521406483de0600dd0060e2
4
- data.tar.gz: 8c3fbef6e765659bbd78ecad72b0003c86ba7215
3
+ metadata.gz: be11f4eed2038e56a193d9f3b865b39dc5622a3e
4
+ data.tar.gz: 6f64927b9332620502acb07eb060bf2888f63e96
5
5
  SHA512:
6
- metadata.gz: a3c8959f866ac3432266b1bb0768aa626e08e960039e63aaff35b8e1956cf14c58890495afd3c09211ca9ee0dc811a92c41253b5db2c5babbe6b5ea0089dd15e
7
- data.tar.gz: ba37f46699b72aa4d5dc4db293a13f3fc739d81fa0464e82b953313030584e4fc6d18335360b466641cad5a615eab4d6e857d0bd5a1357e068b7afa8bf326d82
6
+ metadata.gz: 8cf3a5bbbeb045def4a39a6e11a00e74fb6a0e2d7b94ef5ac95c47ecda07f3773c8d8061c3bae323c005040d7034c12dc722002b9d5ea9581a40e00d37bb6367
7
+ data.tar.gz: c0c85469799ba41b645f8a1e6520eda958b39ed16f3a2d939badc12f471ed9d88515a08590e07ccbb1c13f26b3979cf1b9156f8d26c97aebfcb4583d0ae7d7a4
@@ -2,6 +2,7 @@ require 'typhoeus'
2
2
 
3
3
  require 'skype_bot/card'
4
4
  require 'skype_bot/activity'
5
+ require 'skype_bot/uri'
5
6
  require 'skype_bot/auth'
6
7
  require 'skype_bot/config'
7
8
  require 'skype_bot/parser'
@@ -14,12 +15,12 @@ module SkypeBot
14
15
  yield(Config) if block_given?
15
16
  end
16
17
 
17
- def message(uid, content)
18
- Activity.new(uid).sent(content)
18
+ def message(event, content)
19
+ Activity.new(event).sent(content)
19
20
  end
20
21
 
21
- def card(format, uid, payload)
22
- Card.call(format, uid, payload)
22
+ def card(event, format, payload)
23
+ Card.call(event, format, payload)
23
24
  end
24
25
 
25
26
  def parser(data)
@@ -1,36 +1,36 @@
1
1
  module SkypeBot
2
2
  class Activity
3
- CONVERSATION_URL = 'https://skype.botframework.com/v3/conversations'
3
+ attr_accessor :event
4
4
 
5
- attr_accessor :uid
6
-
7
- def initialize(uid)
8
- @uid = uid
5
+ def initialize(event)
6
+ @event = event
9
7
  end
10
8
 
11
9
  def sent(content)
12
10
  token = Auth.get_token
13
11
  body = payload(content).to_json
14
12
  headers = { Authorization: "Bearer #{token}", 'Content-Type': 'application/json' }
15
-
16
13
  Typhoeus.post(activity_url, body: body, headers: headers)
17
14
  end
18
15
 
19
16
  private
20
17
 
21
18
  def activity_url
22
- "#{CONVERSATION_URL}/#{uid}/activities"
19
+ end_point = Uri.join(event['service_url'], Config.conversation_path, event['conversation_id'], Config.activity_path)
20
+
21
+ if event['id'].present? && event['channel_id'] != 'skype'
22
+ end_point + '/' + event['id']
23
+ else
24
+ end_point
25
+ end
23
26
  end
24
27
 
25
28
  def payload(content)
26
29
  {
27
30
  type: 'message',
28
- agent: 'botbuilder',
29
- source: 'skype',
30
31
  text: content,
31
- from: { id: "#{Config.skype_number}:#{Config.app_id}" },
32
- recipient: { id: uid },
33
- channelData: {}
32
+ from: { id: event['to'], name: event['bot_name'] },
33
+ recipient: { id: event['from'] }
34
34
  }
35
35
  end
36
36
  end
@@ -7,8 +7,8 @@ module SkypeBot
7
7
  module Card
8
8
  extend self
9
9
 
10
- def call(format, uid, payload)
11
- Cards.const_get(format.to_s.classify).new(uid).sent(payload)
10
+ def call(format, event, payload)
11
+ Cards.const_get(format.to_s.classify).new(event).sent(payload)
12
12
  end
13
13
  end
14
14
  end
@@ -1,12 +1,10 @@
1
1
  module SkypeBot
2
2
  module Cards
3
3
  class Base
4
- CONVERSATION_URL = 'https://skype.botframework.com/v3/conversations'
4
+ attr_accessor :event
5
5
 
6
- attr_accessor :uid
7
-
8
- def initialize(uid)
9
- @uid = uid
6
+ def initialize(event)
7
+ @event = event
10
8
  end
11
9
 
12
10
  def sent(data)
@@ -19,21 +17,20 @@ module SkypeBot
19
17
  end
20
18
 
21
19
  def activity_url
22
- "#{CONVERSATION_URL}/#{uid}/activities"
20
+ end_point = Uri.join(event['service_url'], Config.conversation_path, event['conversation_id'], Config.activity_path)
21
+
22
+ if event['id'].present? && event['channel_id'] != 'skype'
23
+ end_point + '/' + event['id']
24
+ else
25
+ end_point
26
+ end
23
27
  end
24
28
 
25
29
  def payload(attachments)
26
30
  {
27
31
  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
- },
32
+ from: { id: event['to'], name: event['bot_name'] },
33
+ recipient: { id: event['from'] },
37
34
  textFormat: 'xml',
38
35
  attachments: attachments
39
36
  }
@@ -5,15 +5,8 @@ module SkypeBot
5
5
  def payload(attachments)
6
6
  {
7
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
- },
8
+ from: { id: event['to'], name: event['bot_name'] },
9
+ recipient: { id: event['from'] },
17
10
  textFormat: 'xml',
18
11
  attachmentLayout: 'carousel',
19
12
  attachments: attachments
@@ -8,5 +8,11 @@ module SkypeBot
8
8
 
9
9
  mattr_accessor :scope
10
10
  @@scope = 'https://graph.microsoft.com/.default'
11
+
12
+ mattr_accessor :conversation_path
13
+ @@conversation_path = '/v3/conversations'
14
+
15
+ mattr_accessor :activity_path
16
+ @@activity_path = '/activities'
11
17
  end
12
18
  end
@@ -8,12 +8,17 @@ module SkypeBot
8
8
 
9
9
  def execute
10
10
  {
11
+ id: payload['id'],
11
12
  type: payload['type'].underscore,
12
13
  from: payload['from']['id'],
13
14
  display_name: payload['from']['name'],
14
15
  to: payload['recipient']['id'],
15
16
  time: Time.parse(payload['timestamp']),
16
- content: payload['text']
17
+ content: payload['text'],
18
+ service_url: payload['serviceUrl'],
19
+ channel_id: payload['channelId'],
20
+ conversation_id: payload['conversation']['id'],
21
+ bot_name: payload['recipient']['name']
17
22
  }
18
23
  end
19
24
  end
@@ -0,0 +1,9 @@
1
+ module SkypeBot
2
+ module Uri
3
+ module_function
4
+
5
+ def join(*parts)
6
+ parts.join('/').gsub(/(?<!\:\/)\/(?!\/)/, '/')
7
+ end
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module SkypeBot
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
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.5
4
+ version: 0.0.6
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-28 00:00:00.000000000 Z
11
+ date: 2016-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -106,6 +106,7 @@ files:
106
106
  - lib/skype_bot/cards/sign_in.rb
107
107
  - lib/skype_bot/config.rb
108
108
  - lib/skype_bot/parser.rb
109
+ - lib/skype_bot/uri.rb
109
110
  - lib/skype_bot/version.rb
110
111
  - skype_bot.gemspec
111
112
  homepage: https://github.com/Coffa/skype_bot