mos-eisley-lambda 0.4.1 → 0.5.0

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
  SHA256:
3
- metadata.gz: 588396c579300500ee9480c4d1582e000fb1d92722ad0f6ae4a44e9f1cc2aefd
4
- data.tar.gz: 9f5ee17355c48a5550f561853b8ce6075978b52f71a6de6fe1f47838d4f5f681
3
+ metadata.gz: 7f47807ff37bc9efd5d01b8745fc9cfb36796876b03dc50cf5b1f5504d75cfb5
4
+ data.tar.gz: a9fef8a47a8f9a7c2a7ca36122f047ecfef781f019e40bbcbf5f7eb6d423861d
5
5
  SHA512:
6
- metadata.gz: 004a47f7f3e51a3d891c2912993365a61ced40cc1ba7bb82ac383c4a8543d19142b66d622097e8b10cae14e7003fb1e2d8aa4f4eeea3e59718a3543d4d5d69a3
7
- data.tar.gz: 6b171f129793e822e3c7755460d93a81c33827c1ce0755fef3c02484cd92d5e487d63f6353d6d6504369b31393fef10e1e4ed62b95a9fa9a520570aa0268c171
6
+ metadata.gz: 19c4a11da675e07f0cd1fd405dbdd1013be87086ad3f93afad9c85f64de9bbc6620beb4a6ff441892ca1590b0e9e3977bfbb2cc343e82b3868ec9bd7a804ec42
7
+ data.tar.gz: 4c0421f4ad6e9655845c11fac9e981e2cb7f44856744a839df504f314947afdc888e475e801aa30572815495fba9da879fb4dc867ece6e52ab1b9fc002dcb462
data/README.md CHANGED
@@ -100,8 +100,8 @@ end
100
100
 
101
101
  ### Helpers
102
102
 
103
- `ME::S3PO` – collection of helpers to analyze/create Slack messages.
104
- `ME::SlackWeb` – methods for sending payloads to Slack Web API calls.
103
+ - `ME::S3PO` – collection of helpers to analyze/create Slack messages.
104
+ - `ME::SlackWeb` – methods for sending payloads to Slack Web API calls.
105
105
 
106
106
  ## Event Lifecycle
107
107
 
@@ -128,7 +128,7 @@ Send a message to SQS from another app to send a Slack message
128
128
 
129
129
  ## Using with Lambda Layers
130
130
 
131
- Used the Makefile to create a zip file which can be uploaded as a Lambda Layer.
131
+ Used the Makefile to create a zip file which can be uploaded to a Lambda Layer.
132
132
 
133
133
  ```sh
134
134
  make
data/lib/slack.rb CHANGED
@@ -48,11 +48,23 @@ module MosEisley
48
48
  post_to_slack('chat.meMessage', data)
49
49
  end
50
50
 
51
- def self.chat_postephemeral()
51
+ def self.chat_postephemeral(channel:, blocks: nil, text: nil, thread_ts: nil)
52
+ chat_send(:postEphemeral, channel, blocks, text, thread_ts)
52
53
  end
53
54
 
54
55
  def self.chat_postmessage(channel:, blocks: nil, text: nil, thread_ts: nil)
56
+ chat_send(:postMessage, channel, blocks, text, thread_ts)
57
+ end
58
+
59
+ def self.chat_schedulemessage(channel:, post_at:, blocks: nil, text: nil, thread_ts: nil)
60
+ chat_send(:scheduleMessage, channel, blocks, text, thread_ts, post_at)
61
+ end
62
+
63
+ def self.chat_send(m, channel, blocks, text, thread_ts, post_at = nil)
55
64
  data = {channel: channel}
65
+ if m == :scheduleMessage
66
+ post_at ? data[:post_at] = post_at : raise
67
+ end
56
68
  if blocks
57
69
  data[:blocks] = blocks
58
70
  data[:text] = text if text
@@ -60,10 +72,7 @@ module MosEisley
60
72
  text ? data[:text] = text : raise
61
73
  end
62
74
  data[:thread_ts] = thread_ts if thread_ts
63
- post_to_slack('chat.postMessage', data)
64
- end
65
-
66
- def self.chat_schedulemessage()
75
+ post_to_slack("chat.#{m}", data)
67
76
  end
68
77
 
69
78
  def self.post_response_url(url, payload)
@@ -111,9 +120,52 @@ module MosEisley
111
120
  def self.views_push(trigger_id:, view:)
112
121
  end
113
122
 
114
- # def self.auth_test
115
- # post_to_slack('auth.test')
116
- # end
123
+ def self.users_info(user)
124
+ users_send('info', {user: user})
125
+ end
126
+
127
+ def self.users_list(cursor: nil, limit: nil)
128
+ params = {include_locale: true}
129
+ params[:cursor] = cursor if cursor
130
+ params[:limit] = limit if limit
131
+ users_send('list', params)
132
+ end
133
+
134
+ def self.users_lookupbyemail(email)
135
+ users_send('lookupByEmail', {email: email})
136
+ end
137
+
138
+ def self.users_profile_get(user)
139
+ users_send('profile.get', {user: user})
140
+ end
141
+
142
+ def self.users_send(m, params)
143
+ l = MosEisley.logger
144
+ call = "users.#{m}"
145
+ url ||= BASE_URL + call
146
+ head = {authorization: "Bearer #{ENV['SLACK_BOT_ACCESS_TOKEN']}"}
147
+ r = Neko::HTTP.get(url, params, head)
148
+ if r[:code] != 200
149
+ l.warn("#{call} HTTP failed: #{r[:message]}")
150
+ return nil
151
+ end
152
+ begin
153
+ h = JSON.parse(r[:body], {symbolize_names: true})
154
+ if h[:ok]
155
+ return h
156
+ else
157
+ l.warn("#{call} Slack failed: #{h[:error]}")
158
+ l.debug("#{h[:response_metadata]}")
159
+ return nil
160
+ end
161
+ rescue
162
+ return {body: r[:body]}
163
+ end
164
+ end
165
+
166
+ def self.auth_test
167
+ post_to_slack('auth.test', '')
168
+ end
117
169
 
118
170
  private
119
171
 
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'mos-eisley-lambda'
3
- s.version = '0.4.1'
3
+ s.version = '0.5.0'
4
4
  s.authors = ['Ken J.']
5
5
  s.email = ['kenjij@gmail.com']
6
6
  s.summary = %q{Ruby based Slack bot framework, for AWS Lambda use}
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mos-eisley-lambda
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ken J.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-27 00:00:00.000000000 Z
11
+ date: 2021-08-14 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Ruby based Slack bot framework, for AWS Lambda use. Also provides helpers
14
14
  to analyze/build messages. Event based utilizing SQS.