Skip to content

Commit b366acf

Browse files
Added the ability to get channel message history.
1 parent 83f3331 commit b366acf

File tree

5 files changed

+41
-6
lines changed

5 files changed

+41
-6
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ language: julia
22

33
julia:
44
- 1.3
5-
5+
66
os: linux
77

88
codecov: true
99
coveralls: true
1010

1111
script:
1212
- julia --project --color=yes --check-bounds=yes -e 'using Pkg; Pkg.instantiate(); Pkg.build();'
13-
- julia --code-coverage test/runtests.jl $Webhook
13+
- julia --code-coverage test/runtests.jl $Webhook $Token
1414

1515

1616
after_success:

src/Slack.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ include("channel.jl")
1313
export
1414
getchannels
1515

16+
include("history.jl")
17+
export
18+
getchannelhistory
19+
1620
# include("utils.jl")
1721
# export
1822
# convert_HTTP_Response_To_JSON

src/channel.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ end
3434
getchannels(token::String)
3535
Takes in the Slack App Auth token and returns a array of channel objects.
3636
The main value in a channel object is the Channel ID and name which you
37-
need in order to send threaded messages to Slack.
37+
need in order to send threaded messages to Slack.
38+
39+
Tokens can be accessed at "https://api.slack.com/apps/random-letters-and-numbers/oauth?"
3840
"""
3941
function getchannels(token::String)
4042

@@ -98,7 +100,7 @@ function getchannels(token::String)
98100
num_members = value
99101
elseif occursin("is_im", key)
100102
is_im = value
101-
elseif occursin("id", key)
103+
elseif "id" == key
102104
id = value
103105
elseif occursin("created", key)
104106
created = value
@@ -132,7 +134,7 @@ function getchannels(token::String)
132134
# println("$(key) $(value)") #DEBUG
133135
end
134136
new_channel = channel(is_private, pending_connected_team_ids, topic, is_archived, is_general,
135-
is_mpim, name, previous_names, num_members, is_im, id[1], created, name_normalized,
137+
is_mpim, name, previous_names, num_members, is_im, id, created, name_normalized,
136138
is_group, purpose, creator, is_channel, pending_shared, is_shared, is_ext_shared,
137139
shared_team_ids, is_member, parent_conversation, is_pending_ext_shared, is_org_shared)
138140

src/history.jl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"""
2+
getchannelhistory(token::String)
3+
Takes in the Slack App Auth token and channel ID.
4+
5+
Tokens can be accessed at "https://api.slack.com/apps/random-letters-and-numbers/oauth?"
6+
"""
7+
function getchannelhistory(token::String, channelid::String)
8+
HTTP.setuseragent!("HTTP.jl")
9+
10+
url = "https://slack.com/api/conversations.history?token=$(token)&channel=$(channelid)"
11+
12+
r = HTTP.get(url, ["Content-Type" => "application/json"])
13+
14+
json_obj = JSON.parse(String(r.body))
15+
message_holder = []
16+
for (k,v) in json_obj
17+
if occursin("messages", k)
18+
for item in v
19+
for (key,value) in item
20+
print(key, " ", value)
21+
#TODO Make a Messages Struct and then add the message info to the object.
22+
end
23+
end
24+
end
25+
end
26+
27+
end

test/runtests.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ using Slack
22
using Test
33

44
endpoint = ARGS[1]
5+
token = ARGS[2]
6+
57

68
data = "Hello World"
79
attachment = Dict("attachments" => [Dict("fallback" => "Required plain-text summary of the attachment",
@@ -25,5 +27,5 @@ response = sendtoslack(data, endpoint)
2527
response2 = sendattachmenttoslack(attachment, endpoint)
2628
@test response2 == "ok"
2729

28-
response3 = getchannels("xoxp-845623957106-858416094789-850474976673-fbe1028a5c118dbea47abe55096bee55")
30+
response3 = getchannels(token)
2931
println(response3)

0 commit comments

Comments
 (0)