-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathslackDemo.ur
36 lines (30 loc) · 1.29 KB
/
slackDemo.ur
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
(* For this demo, it's necessary to create slackSecrets.urs,
* defining [token]. *)
structure S = Slack.Make(Slack.TwoLegged(SlackSecrets))
fun postMessage ch text =
Monad.ignore (S.Chat.postMessage {Channel = ch, Text = text})
fun channel ch =
text <- source "";
ms <- S.Conversations.history ch;
ms <- List.mapM (fn m =>
user <- S.Users.info m.User;
return (user.Nam, user.RealName, m.Text)) ms;
return <xml><body>
<ol>
{List.mapX (fn (user, rname, text) => <xml><li>{[user]} <i>({[rname]})</i>: {[text]}</li></xml>) ms}
</ol>
<hr/>
Post message: <ctextbox source={text}/> <button value="Go" onclick={fn _ => text <- get text; rpc (postMessage ch text); redirect (url (channel ch))}/>
</body></xml>
fun newChannel name =
Monad.ignore (S.Conversations.create name)
fun main () =
name <- source "";
chs <- S.Conversations.list;
return <xml><body>
<ul>
{List.mapX (fn ch => <xml><li><a href={S.Conversations.url ch}>{[ch.Nam]}</a> <a link={channel ch.Id}>[more]</a></li></xml>) chs}
</ul>
<hr/>
Create channel: <ctextbox source={name}/> <button value="Go" onclick={fn _ => name <- get name; rpc (newChannel name); redirect (url (main ()))}/>
</body></xml>