-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathpoll-bot.swadl.yaml
64 lines (61 loc) · 1.79 KB
/
poll-bot.swadl.yaml
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
id: poll
variables:
answer1: 0
answer2: 0
activities:
- send-message:
id: createPoll
on:
message-received:
content: /poll
# should be 1-1 only
content: |
<messageML>
<form id="createPoll">
<text-field name="room" placeholder="Room" required="true"/>
<text-field name="question" placeholder="What is your question?" required="true"/>
<text-field name="answer1" placeholder="Answer 1" required="true"/>
<text-field name="answer2" placeholder="Answer 2" required="true"/>
<button name="send-answers" type="action">Create poll</button>
</form>
</messageML>
- send-message:
id: poll
on:
form-replied:
form-id: createPoll
to:
stream-id: ${createPoll.room}
content:
<messageML>
<form id="poll">
${createPoll.question}
<radio name="answers" value="1">${createPoll.answer1}</radio>
<radio name="answers" value="2">${createPoll.answer2}</radio>
<button name="send-answers" type="action">This is my choice!</button>
</form>
</messageML>
- execute-script:
id: collectReplies
on:
form-replied:
form-id: poll
script:
if (poll.answers == "1") {
variables.answer1++
} else if (poll.answers == "2") {
variables.answer2++
}
- send-message:
id: showReply
on:
timeout: PT30S
activity-expired:
activity-id: collectReplies
to:
stream-id: ${createPoll.room}
content: |
<h1>Poll ended!</h1>
${createPoll.answer1}: ${variables.answer1}
<br/>
${createPoll.answer2}: ${variables.answer2}