Commit 6008670
Add !quiz command (#360)
* SlackerBot Event Handler:
- Added logic to handle Slack interactive message responses for the quiz feature.
- Implemented content-type based logic to differentiate between Default messages, Challenge requests and Quiz interactions.
- Captured and processed the user selected quiz answer, comparing it against the correct answer.
- Updated the bot to send a response message back to the user indicating whether the answer was correct or not.
* Create a new SN Quiz.js
- Implemented functionality to capture the quiz topic from the Slack command using regex.
- Integrated OpenAI API to generate multiple-choice quiz questions dynamically based on the quiz topic provided.
- Processed and formatted the AI response into structured JSON, containing the question, options, correct answer, and explanation.
- Enhanced Slack integration using Block Kit to present the quiz question with interactive buttons for each option.
* Scripted Rest API:
- Updated the interaction script to validate user selections and provide feedback based on the correctness of the response.
- Added dynamic button styling (primary/danger) to visually indicate correct and incorrect answers.
- Improved feedback messages with detailed explanations for correct answers.
- Integrated the update_chat method to ensure real-time message updates in Slack with button styling and quiz results.
Slacker Script Include:
- Enhanced maintainability by centralizing the Slack message update logic in a dedicated Script Include function.
* Update - Create a new SN Quiz.js
- Added error handling to manage unexpected responses from the OpenAI API.
- Improved user interaction by formatting the question and answers using Slack Block Kit.
- Ensured that correct answers are validated and passed along with the user selection for feedback.
* Update Create a new SN Quiz.js
Initial comments inserted
* The API - Event Handler has been updated with some adjustments and improvements:
- Fix: The Script Include Slacker() is no longer instantiated twice.
- The block only accepts interaction if the user interacting with the block is the same user who sent the command.
- All other blocks automatically turn red after the user selects the correct option.
- Now the bot briefly explains why the option is correct.
- A note has been added so the user knows that only the person who sent the command can answer the question.
* Update Create a new SN Quiz.js
The script has been updated with some adjustments and improvements:
- The model used in the OpenAI integration has been changed to gpt-4o.
- The ID of the user who asked the question is being retrieved and sent for interaction validation.
- A greeting was added to the quiz so that the person who asked the question knows it is directed at them.
- A note has been added to inform the user that only the person who sent the command can answer the quiz.
* A new function has been created to validate whether the bot can interact in the channel.
The function checks if the original message was sent by a user and if the interaction is of the type “block_actions” - Necessary for setting up the quiz.
The function checks if the interaction contains a bot_id, and if it does, two things are validated:
1. If the type of interaction is “message_changed” - Necessary for the bot to update the styles of the blocks (colors).
2. If the thread was started by a user - Necessary for the bot to respond to the correct question. This way, it does not get stuck in a loop responding to itself.
If the interaction does not have a bot_id, then the message can be sent.
---------
Co-authored-by: admin <admin@example.com>
Co-authored-by: Astrid Sapphire <59789839+SapphicFire@users.noreply.github.com>1 parent 64407b5 commit 6008670
4 files changed
Lines changed: 268 additions & 25 deletions
File tree
- Parsers
- b02cf9e61b861d10d806dc23b24bcb3f
- update
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 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 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
Lines changed: 34 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| |||
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
76 | 102 | | |
77 | 103 | | |
78 | 104 | | |
| |||
109 | 135 | | |
110 | 136 | | |
111 | 137 | | |
112 | | - | |
| 138 | + | |
113 | 139 | | |
114 | 140 | | |
115 | 141 | | |
| |||
160 | 186 | | |
161 | 187 | | |
162 | 188 | | |
163 | | - | |
| 189 | + | |
164 | 190 | | |
165 | 191 | | |
166 | 192 | | |
167 | 193 | | |
168 | 194 | | |
169 | | - | |
170 | | - | |
| 195 | + | |
| 196 | + | |
171 | 197 | | |
172 | 198 | | |
Lines changed: 119 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | | - | |
| 4 | + | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
| 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 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
24 | 124 | | |
25 | 125 | | |
26 | 126 | | |
| |||
36 | 136 | | |
37 | 137 | | |
38 | 138 | | |
| 139 | + | |
39 | 140 | | |
40 | 141 | | |
41 | 142 | | |
42 | 143 | | |
43 | 144 | | |
| 145 | + | |
| 146 | + | |
44 | 147 | | |
45 | 148 | | |
46 | 149 | | |
| |||
0 commit comments