skype_bot 0.0.5 → 0.0.6
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/lib/skype_bot.rb +5 -4
- data/lib/skype_bot/activity.rb +12 -12
- data/lib/skype_bot/card.rb +2 -2
- data/lib/skype_bot/cards/base.rb +12 -15
- data/lib/skype_bot/cards/carousel.rb +2 -9
- data/lib/skype_bot/config.rb +6 -0
- data/lib/skype_bot/parser.rb +6 -1
- data/lib/skype_bot/uri.rb +9 -0
- data/lib/skype_bot/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be11f4eed2038e56a193d9f3b865b39dc5622a3e
|
4
|
+
data.tar.gz: 6f64927b9332620502acb07eb060bf2888f63e96
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8cf3a5bbbeb045def4a39a6e11a00e74fb6a0e2d7b94ef5ac95c47ecda07f3773c8d8061c3bae323c005040d7034c12dc722002b9d5ea9581a40e00d37bb6367
|
7
|
+
data.tar.gz: c0c85469799ba41b645f8a1e6520eda958b39ed16f3a2d939badc12f471ed9d88515a08590e07ccbb1c13f26b3979cf1b9156f8d26c97aebfcb4583d0ae7d7a4
|
data/lib/skype_bot.rb
CHANGED
@@ -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(
|
18
|
-
Activity.new(
|
18
|
+
def message(event, content)
|
19
|
+
Activity.new(event).sent(content)
|
19
20
|
end
|
20
21
|
|
21
|
-
def card(
|
22
|
-
Card.call(
|
22
|
+
def card(event, format, payload)
|
23
|
+
Card.call(event, format, payload)
|
23
24
|
end
|
24
25
|
|
25
26
|
def parser(data)
|
data/lib/skype_bot/activity.rb
CHANGED
@@ -1,36 +1,36 @@
|
|
1
1
|
module SkypeBot
|
2
2
|
class Activity
|
3
|
-
|
3
|
+
attr_accessor :event
|
4
4
|
|
5
|
-
|
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
|
-
|
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:
|
32
|
-
recipient: { id:
|
33
|
-
channelData: {}
|
32
|
+
from: { id: event['to'], name: event['bot_name'] },
|
33
|
+
recipient: { id: event['from'] }
|
34
34
|
}
|
35
35
|
end
|
36
36
|
end
|
data/lib/skype_bot/card.rb
CHANGED
@@ -7,8 +7,8 @@ module SkypeBot
|
|
7
7
|
module Card
|
8
8
|
extend self
|
9
9
|
|
10
|
-
def call(format,
|
11
|
-
Cards.const_get(format.to_s.classify).new(
|
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
|
data/lib/skype_bot/cards/base.rb
CHANGED
@@ -1,12 +1,10 @@
|
|
1
1
|
module SkypeBot
|
2
2
|
module Cards
|
3
3
|
class Base
|
4
|
-
|
4
|
+
attr_accessor :event
|
5
5
|
|
6
|
-
|
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
|
-
|
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
|
-
|
29
|
-
|
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
|
-
|
9
|
-
|
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
|
data/lib/skype_bot/config.rb
CHANGED
@@ -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
|
data/lib/skype_bot/parser.rb
CHANGED
@@ -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
|
data/lib/skype_bot/version.rb
CHANGED
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
|
+
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
|
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
|