ilink 0.1.4 → 0.1.5
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/README.md +3 -3
- data/lib/ilink/bot.rb +21 -15
- data/lib/ilink/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fe6b67ecb39bbb9da2cb397751809a29f751383a03a6d3dc093fbf58e8e5c331
|
|
4
|
+
data.tar.gz: 951690d2c4a09ed83665e71d017284caf2ab981a73421ceae147ebaa0fc01b55
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 67f1002aaf4aac53ac8011201020658f8a5f6c2c526891cf92f38c1488933bb00d4cbadd7578812f7119eaf0d0935b7882ee461e58f5f12b1859336b50693669
|
|
7
|
+
data.tar.gz: cd74028d81ac59acf895c5d47370da489966969f9c07e6dd7d53d667e2570fad7bf0d089411d707ff4677757343ef14d238129bcd3b535d331e17fcfa46a2472
|
data/README.md
CHANGED
|
@@ -56,12 +56,12 @@ bot = ILink::Bot.new(
|
|
|
56
56
|
bot = ILink::Bot.new
|
|
57
57
|
|
|
58
58
|
# Step 1: Get a QR code
|
|
59
|
-
qr = bot.
|
|
59
|
+
qr = bot.get_qrcode
|
|
60
60
|
puts qr[:qrcode_img_content] # QR code image URL — show to user
|
|
61
61
|
|
|
62
62
|
# Step 2: Poll scan status (long-poll, blocks until scanned or timeout)
|
|
63
63
|
loop do
|
|
64
|
-
status = bot.
|
|
64
|
+
status = bot.get_qrcode_status(qrcode: qr[:qrcode])
|
|
65
65
|
case status[:status]
|
|
66
66
|
when "confirmed"
|
|
67
67
|
puts "Login success!"
|
|
@@ -133,7 +133,7 @@ bot.send_message({
|
|
|
133
133
|
### Media Upload
|
|
134
134
|
|
|
135
135
|
```ruby
|
|
136
|
-
resp = bot.
|
|
136
|
+
resp = bot.get_upload_url(
|
|
137
137
|
media_type: ILink::UploadMediaType::IMAGE,
|
|
138
138
|
to_user_id: "user_id",
|
|
139
139
|
rawsize: File.size("photo.jpg"),
|
data/lib/ilink/bot.rb
CHANGED
|
@@ -6,7 +6,7 @@ module ILink
|
|
|
6
6
|
# bot = ILink::Bot.new(token: "your_bot_token")
|
|
7
7
|
# bot.get_updates
|
|
8
8
|
# bot.send_text(to: "user_id", text: "Hello!")
|
|
9
|
-
# bot.
|
|
9
|
+
# bot.get_upload_url(media_type: 1, to_user_id: "user_id", ...)
|
|
10
10
|
# bot.send_typing(user_id: "...", ticket: "...")
|
|
11
11
|
# bot.get_config(user_id: "...")
|
|
12
12
|
# bot.create_qr_code
|
|
@@ -36,14 +36,6 @@ module ILink
|
|
|
36
36
|
{ ret: 0, msgs: [], get_updates_buf: buf }
|
|
37
37
|
end
|
|
38
38
|
|
|
39
|
-
# Send a message.
|
|
40
|
-
#
|
|
41
|
-
# @param message [Hash] a WeixinMessage hash with keys like :to_user_id, :item_list, etc.
|
|
42
|
-
# @return [Hash] parsed response
|
|
43
|
-
def send_message(message)
|
|
44
|
-
connection.post("/ilink/bot/sendmessage", { msg: message })
|
|
45
|
-
end
|
|
46
|
-
|
|
47
39
|
# Convenience: send a text message to a user.
|
|
48
40
|
#
|
|
49
41
|
# @param to [String] target user ID
|
|
@@ -63,12 +55,20 @@ module ILink
|
|
|
63
55
|
send_message(message)
|
|
64
56
|
end
|
|
65
57
|
|
|
58
|
+
# Send a message.
|
|
59
|
+
#
|
|
60
|
+
# @param message [Hash] a WeixinMessage hash with keys like :to_user_id, :item_list, etc.
|
|
61
|
+
# @return [Hash] parsed response
|
|
62
|
+
def send_message(message)
|
|
63
|
+
connection.post("/ilink/bot/sendmessage", { msg: message })
|
|
64
|
+
end
|
|
65
|
+
|
|
66
66
|
# Get a pre-signed CDN upload URL.
|
|
67
67
|
#
|
|
68
68
|
# @param params [Hash] :filekey, :media_type, :to_user_id, :rawsize, :rawfilemd5,
|
|
69
69
|
# :filesize, :aeskey, :thumb_rawsize, :thumb_rawfilemd5, :thumb_filesize, :no_need_thumb
|
|
70
70
|
# @return [Hash] { upload_param:, thumb_upload_param:, upload_full_url: }
|
|
71
|
-
def
|
|
71
|
+
def get_upload_url(**params)
|
|
72
72
|
connection.post("/ilink/bot/getuploadurl", params)
|
|
73
73
|
end
|
|
74
74
|
|
|
@@ -78,7 +78,7 @@ module ILink
|
|
|
78
78
|
# @param ticket [String] typing ticket (from get_config)
|
|
79
79
|
# @return [Hash]
|
|
80
80
|
def send_typing(user_id:, ticket:)
|
|
81
|
-
|
|
81
|
+
toggle_typing(user_id: user_id, ticket: ticket, status: TypingStatus::TYPING)
|
|
82
82
|
end
|
|
83
83
|
|
|
84
84
|
# Cancel a typing indicator.
|
|
@@ -87,10 +87,16 @@ module ILink
|
|
|
87
87
|
# @param ticket [String] typing ticket
|
|
88
88
|
# @return [Hash]
|
|
89
89
|
def cancel_typing(user_id:, ticket:)
|
|
90
|
-
|
|
90
|
+
toggle_typing(user_id: user_id, ticket: ticket, status: TypingStatus::CANCEL)
|
|
91
91
|
end
|
|
92
92
|
|
|
93
|
-
|
|
93
|
+
# Toggle a typing indicator.
|
|
94
|
+
#
|
|
95
|
+
# @param user_id [String] ilink user ID
|
|
96
|
+
# @param ticket [String] typing ticket
|
|
97
|
+
# @param status [Integer] typing status (TypingStatus::TYPING or TypingStatus::CANCEL)
|
|
98
|
+
# @return [Hash]
|
|
99
|
+
def toggle_typing(user_id:, ticket:, status:)
|
|
94
100
|
connection.post("/ilink/bot/sendtyping", {
|
|
95
101
|
ilink_user_id: user_id,
|
|
96
102
|
typing_ticket: ticket,
|
|
@@ -112,7 +118,7 @@ module ILink
|
|
|
112
118
|
#
|
|
113
119
|
# @param bot_type [String] bot type identifier (default "3")
|
|
114
120
|
# @return [Hash] { qrcode:, qrcode_img_content: }
|
|
115
|
-
def
|
|
121
|
+
def get_qrcode(bot_type: "3")
|
|
116
122
|
connection.get("/ilink/bot/get_bot_qrcode?bot_type=#{URI.encode_www_form_component(bot_type)}", timeout: 5)
|
|
117
123
|
end
|
|
118
124
|
|
|
@@ -120,7 +126,7 @@ module ILink
|
|
|
120
126
|
#
|
|
121
127
|
# @param qrcode [String] qrcode value from #create_qr_code
|
|
122
128
|
# @return [Hash] { status:, bot_token:, ilink_bot_id:, baseurl:, ilink_user_id:, redirect_host: }
|
|
123
|
-
def
|
|
129
|
+
def get_qrcode_status(qrcode:)
|
|
124
130
|
connection.get("/ilink/bot/get_qrcode_status?qrcode=#{URI.encode_www_form_component(qrcode)}",
|
|
125
131
|
timeout: @configuration.long_poll_timeout)
|
|
126
132
|
rescue Net::ReadTimeout, Net::OpenTimeout
|
data/lib/ilink/version.rb
CHANGED