Skip to content

Commit

Permalink
Introduce Interaction support to Slacker (#432)
Browse files Browse the repository at this point in the history
* feat: introduce interactivity support

added: Interaction table
added: Payload type to Payload to discern events and Interactivity
added: New endpoint to insert Interactions
updated: Filters on payload table BRs
updated: Updated repo event endpoint to handle Interactions

* Add Interactions path for workflow

change: Add interactions path
test: Change Deployment repository

* feat: Migrate the quiz functionality to an Interaction

added: first interaction handler and path

* Interaction support (#11) (#12)

* feat: introduce interactivity support

added: Interaction table
added: Payload type to Payload to discern events and Interactivity
added: New endpoint to insert Interactions
updated: Filters on payload table BRs
updated: Updated repo event endpoint to handle Interactions

* Add Interactions path for workflow

change: Add interactions path
test: Change Deployment repository

* feat: Migrate the quiz functionality to an Interaction

added: first interaction handler and path

* tweak: Update path

* tweak: Change directory name

* fix: Update variable name

* fix: url variable

* Delete Interactions/Handle an SN quiz.js

* tweak: Repoint to correct repo
  • Loading branch information
SapphicFire authored Oct 25, 2024
1 parent 8d78707 commit 06cfe5d
Show file tree
Hide file tree
Showing 41 changed files with 1,686 additions and 281 deletions.
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
push:
paths:
- Parsers/**
- Interaction/**
# branches: [ "main" ]
# pull_request:
# branches: [ "main" ]
Expand Down
69 changes: 69 additions & 0 deletions Interaction/Handle an SN quiz.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
action_id_regex:quiz_answer_
parsers:Create a new SN Quiz
*/

(function (current) {
var slackerProvider = new x_snc_slackerbot.Slacker();
var interactionPayload = JSON.parse(current.getValue('payload'));

// Get selected option, correct option, the user ID that initiated the quiz, and explanation
var action = interactionPayload.actions[0];
var selectedOption = action.value;
var parts = selectedOption.split("|");
var userSelection = parts[0];
var correctOption = parts[1];
var originalUserId = parts[2];
var explanation = parts[3];

// Verify if the interacting user is the same as the original user
if (interactionPayload.user.id !== originalUserId) return;

// Apply styles to each button based on whether it was selected and whether it's correct
var blocks = interactionPayload.message.blocks;
var correctIndex = parseInt(correctOption.split('_')[1]) - 1;

blocks[1].elements.forEach(function (button, index) {
if (userSelection === correctOption) {
button.style = (index === correctIndex) ? "primary" : "danger";
} else {
if (button.value === selectedOption) {
button.style = "danger";
}
}
});

var updateMessagePayload = {
"channel": interactionPayload.channel.id,
"ts": interactionPayload.message.ts,
"blocks": blocks,
"text": "UpdatingQuiz"
};

var responseMessageUpdated = slackerProvider.update_chat(updateMessagePayload);

// Validate User Answer and send appropriate feedback
var current = {
"text": interactionPayload.message.blocks[0].text.text,
"ts": interactionPayload.message.ts,
"thread_ts": interactionPayload.container.message_ts,
"channel": interactionPayload.channel.id,
"user": {
"user_id": interactionPayload.user.id,
"name": interactionPayload.user.name
}
};

var questionText = interactionPayload.message.blocks[0].text.text;
var textLines = questionText.split("\n");
var correctAnswerText = textLines[correctIndex + 4].trim();
var correctAnswer = correctAnswerText.replace(/^[A-D]\)\s*/, '');

if (userSelection === correctOption) {
var correctMessage = "Well done! The correct answer is:\n*" + correctAnswer + "*\n\n" + explanation;
slackerProvider.send_chat(current, correctMessage, false);
} else {
var incorrectMessage = "Oops, not quite! Try Again.";
slackerProvider.send_chat(current, incorrectMessage, false);
}
})(current);
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?><record_update>
<sys_choice action="INSERT_OR_UPDATE" field="payload_type" table="x_snc_slackerbot_payload" version="3">
<sys_choice_set action="INSERT_OR_UPDATE">
<element>payload_type</element>
<name>x_snc_slackerbot_payload</name>
<sys_class_name>sys_choice_set</sys_class_name>
<sys_created_by>asteroid</sys_created_by>
<sys_created_on>2024-10-20 08:14:42</sys_created_on>
<sys_mod_count>0</sys_mod_count>
<sys_name>payload_type</sys_name>
<sys_package display_value="SlackerBot" source="x_snc_slackerbot">b02cf9e61b861d10d806dc23b24bcb3f</sys_package>
<sys_policy/>
<sys_scope display_value="SlackerBot">b02cf9e61b861d10d806dc23b24bcb3f</sys_scope>
<sys_update_name>sys_choice_x_snc_slackerbot_payload_payload_type</sys_update_name>
<sys_updated_by>asteroid</sys_updated_by>
<sys_updated_on>2024-10-20 08:14:42</sys_updated_on>
</sys_choice_set>
<sys_choice action="INSERT_OR_UPDATE">
<dependent_value/>
<element>payload_type</element>
<hint/>
<inactive>false</inactive>
<label>Event</label>
<language>en</language>
<name>x_snc_slackerbot_payload</name>
<sequence>1</sequence>
<synonyms/>
<sys_created_by>asteroid</sys_created_by>
<sys_created_on>2024-10-20 08:14:42</sys_created_on>
<sys_domain>global</sys_domain>
<sys_domain_path>/</sys_domain_path>
<sys_mod_count>0</sys_mod_count>
<sys_updated_by>asteroid</sys_updated_by>
<sys_updated_on>2024-10-20 08:14:42</sys_updated_on>
<value>event</value>
</sys_choice>
<sys_choice action="INSERT_OR_UPDATE">
<dependent_value/>
<element>payload_type</element>
<hint/>
<inactive>false</inactive>
<label>Interaction</label>
<language>en</language>
<name>x_snc_slackerbot_payload</name>
<sequence>2</sequence>
<synonyms/>
<sys_created_by>asteroid</sys_created_by>
<sys_created_on>2024-10-20 08:15:43</sys_created_on>
<sys_domain>global</sys_domain>
<sys_domain_path>/</sys_domain_path>
<sys_mod_count>0</sys_mod_count>
<sys_updated_by>asteroid</sys_updated_by>
<sys_updated_on>2024-10-20 08:15:43</sys_updated_on>
<value>interaction</value>
</sys_choice>
</sys_choice>
</record_update>
2 changes: 1 addition & 1 deletion b02cf9e61b861d10d806dc23b24bcb3f/checksum.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
xq9ZwXwxj-LQZscVtqBmLSrZuGf_Q2oGZeXqw9RlyMvbCJKoCxdk9bya90x3WFbGbMisVjO2PuDoCZtBzEVfOQWWEMynig8CKFb5Ntmxo_8QHpxll6_mbnHi7r1hK4YAENeehyK39yQw2kw3lTF2Sa6EJV-5XlLbKTLhzJJO2-x1CDCu_7pRZ_wY7aMyZeq6WS74Ki4YhVXnsGHngFiEbix6quageR5toLquzGYVvmO2ZxW4WQhlK3IToa0lswO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yG5n6Ap1tSwiI_CeV_bWYrJt-Ok4wEroDs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?><database>
<element db_object_id="ee0be417c3dd165055bdd523e401314f" label="Interaction" max_length="40" name="x_snc_slackerbot_interaction" type="collection">
<element label="Action ID regex" max_length="128" name="action_id_regex" type="string"/>
<element display="true" label="Description" max_length="128" name="description" type="string"/>
<element default="true" function_definition="true" label="Active" max_length="40" name="active" type="boolean"/>
<element label="Script" max_length="8000" name="script" type="script"/>
<element label="Related parsers" max_length="4000" name="related_parsers" reference="x_snc_slackerbot_parser" type="glide_list"/>
</element>
</database>
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?><database>
<element db_object_id="cd63611a47602110e628d855d36d43c1" label="Payload" max_length="40" name="x_snc_slackerbot_payload" type="collection">
<element attributes="edge_encryption_enabled=true" label="Channel" max_length="40" name="channel" type="string"/>
<element attributes="json_view=true" label="Payload" max_length="4000" name="payload" read_only="true" type="string"/>
<element attributes="edge_encryption_enabled=true" label="Timestamp" max_length="40" name="ts" type="string"/>
<element attributes="edge_encryption_enabled=true" label="Channel" max_length="40" name="channel" type="string"/>
<element choice="1" default="event" label="Payload type" max_length="40" name="payload_type" type="choice">
<choice>
<element inactive_on_update="false" label="Event" sequence="1" value="event"/>
<element inactive_on_update="false" label="Interaction" sequence="2" value="interaction"/>
</choice>
</element>
</element>
</database>
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?><record_update sys_domain="global" table="sys_app_module">
<sys_app_module action="INSERT_OR_UPDATE">
<active>true</active>
<application display_value="SlackerBot">b56dfd2a1b861d10d806dc23b24bcb52</application>
<assessment/>
<device_type/>
<filter/>
<hint/>
<homepage/>
<image/>
<link_type>LIST</link_type>
<map_page/>
<mobile_title>Interactions</mobile_title>
<mobile_view_name>Mobile</mobile_view_name>
<name>x_snc_slackerbot_interaction</name>
<order/>
<override_menu_roles>false</override_menu_roles>
<query/>
<report/>
<require_confirmation>true</require_confirmation>
<roles/>
<sys_class_name>sys_app_module</sys_class_name>
<sys_created_by>asteroid</sys_created_by>
<sys_created_on>2024-10-24 10:21:28</sys_created_on>
<sys_domain>global</sys_domain>
<sys_domain_path>/</sys_domain_path>
<sys_id>82da0f3bc3d15a5055bdd523e40131ae</sys_id>
<sys_mod_count>0</sys_mod_count>
<sys_name>Interactions</sys_name>
<sys_overrides/>
<sys_package display_value="SlackerBot" source="x_snc_slackerbot">b02cf9e61b861d10d806dc23b24bcb3f</sys_package>
<sys_policy/>
<sys_scope display_value="SlackerBot">b02cf9e61b861d10d806dc23b24bcb3f</sys_scope>
<sys_update_name>sys_app_module_82da0f3bc3d15a5055bdd523e40131ae</sys_update_name>
<sys_updated_by>asteroid</sys_updated_by>
<sys_updated_on>2024-10-24 10:21:28</sys_updated_on>
<timeline_page/>
<title>Interactions</title>
<uncancelable>false</uncancelable>
<view_name/>
<window_name/>
</sys_app_module>
</record_update>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?><record_update table="sys_db_object">
<sys_db_object action="INSERT_OR_UPDATE">
<access/>
<actions_access>true</actions_access>
<alter_access>true</alter_access>
<caller_access/>
<client_scripts_access>true</client_scripts_access>
<configuration_access>false</configuration_access>
<create_access>true</create_access>
<create_access_controls>false</create_access_controls>
<delete_access>false</delete_access>
<is_extendable>false</is_extendable>
<label>Interaction</label>
<live_feed_enabled>false</live_feed_enabled>
<name>x_snc_slackerbot_interaction</name>
<number_ref/>
<provider_class/>
<read_access>true</read_access>
<scriptable_table>false</scriptable_table>
<super_class/>
<sys_class_name>sys_db_object</sys_class_name>
<sys_created_by>asteroid</sys_created_by>
<sys_created_on>2024-10-22 09:25:37</sys_created_on>
<sys_id>ee0be417c3dd165055bdd523e401314f</sys_id>
<sys_mod_count>0</sys_mod_count>
<sys_name>Slackerbot Interaction</sys_name>
<sys_package display_value="SlackerBot" source="x_snc_slackerbot">b02cf9e61b861d10d806dc23b24bcb3f</sys_package>
<sys_policy/>
<sys_scope display_value="SlackerBot">b02cf9e61b861d10d806dc23b24bcb3f</sys_scope>
<sys_update_name>sys_db_object_ee0be417c3dd165055bdd523e401314f</sys_update_name>
<sys_updated_by>asteroid</sys_updated_by>
<sys_updated_on>2024-10-22 09:25:37</sys_updated_on>
<update_access>true</update_access>
<user_role/>
<ws_access>true</ws_access>
</sys_db_object>
</record_update>
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?xml version="1.0" encoding="UTF-8"?><record_update>
<sys_dictionary action="INSERT_OR_UPDATE" element="action_id_regex" table="x_snc_slackerbot_interaction">
<active>true</active>
<array>false</array>
<attributes/>
<audit>false</audit>
<calculation><![CDATA[(function calculatedFieldValue(current) {
// Add your code here
return ''; // return the calculated value
})(current);]]></calculation>
<choice/>
<choice_field/>
<choice_table/>
<column_label>Action ID regex</column_label>
<comments/>
<create_roles/>
<default_value/>
<defaultsort/>
<delete_roles/>
<dependent/>
<dependent_on_field/>
<display>false</display>
<dynamic_creation>false</dynamic_creation>
<dynamic_creation_script/>
<dynamic_default_value/>
<dynamic_ref_qual/>
<element>action_id_regex</element>
<element_reference>false</element_reference>
<foreign_database/>
<formula/>
<function_definition/>
<function_field>false</function_field>
<internal_type display_value="String">string</internal_type>
<mandatory>false</mandatory>
<max_length>128</max_length>
<name>x_snc_slackerbot_interaction</name>
<next_element/>
<primary>false</primary>
<read_only>false</read_only>
<read_roles/>
<reference/>
<reference_cascade_rule/>
<reference_floats>false</reference_floats>
<reference_key/>
<reference_qual/>
<reference_qual_condition/>
<reference_type/>
<spell_check>false</spell_check>
<staged>false</staged>
<sys_class_name>sys_dictionary</sys_class_name>
<sys_created_by>asteroid</sys_created_by>
<sys_created_on>2024-10-22 09:33:05</sys_created_on>
<sys_name>Action ID regex</sys_name>
<sys_package display_value="SlackerBot" source="x_snc_slackerbot">b02cf9e61b861d10d806dc23b24bcb3f</sys_package>
<sys_policy/>
<sys_scope display_value="SlackerBot">b02cf9e61b861d10d806dc23b24bcb3f</sys_scope>
<sys_update_name>sys_dictionary_x_snc_slackerbot_interaction_action_id_regex</sys_update_name>
<sys_updated_by>asteroid</sys_updated_by>
<sys_updated_on>2024-10-22 09:36:34</sys_updated_on>
<table_reference>false</table_reference>
<text_index>false</text_index>
<unique>false</unique>
<use_dependent_field>false</use_dependent_field>
<use_dynamic_default>false</use_dynamic_default>
<use_reference_qualifier>simple</use_reference_qualifier>
<virtual>false</virtual>
<virtual_type>script</virtual_type>
<widget/>
<write_roles/>
<xml_view>false</xml_view>
</sys_dictionary>
</record_update>
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?xml version="1.0" encoding="UTF-8"?><record_update>
<sys_dictionary action="INSERT_OR_UPDATE" element="active" table="x_snc_slackerbot_interaction">
<active>true</active>
<array>false</array>
<attributes/>
<audit>false</audit>
<calculation><![CDATA[(function calculatedFieldValue(current) {
// Add your code here
return ''; // return the calculated value
})(current);]]></calculation>
<choice/>
<choice_field/>
<choice_table/>
<column_label>Active</column_label>
<comments/>
<create_roles/>
<default_value>true</default_value>
<defaultsort/>
<delete_roles/>
<dependent/>
<dependent_on_field/>
<display>false</display>
<dynamic_creation>false</dynamic_creation>
<dynamic_creation_script/>
<dynamic_default_value/>
<dynamic_ref_qual/>
<element>active</element>
<element_reference>false</element_reference>
<foreign_database/>
<formula/>
<function_definition>true</function_definition>
<function_field>false</function_field>
<internal_type display_value="">boolean</internal_type>
<mandatory>false</mandatory>
<max_length>40</max_length>
<name>x_snc_slackerbot_interaction</name>
<next_element/>
<primary>false</primary>
<read_only>false</read_only>
<read_roles/>
<reference/>
<reference_cascade_rule/>
<reference_floats>false</reference_floats>
<reference_key/>
<reference_qual/>
<reference_qual_condition/>
<reference_type/>
<spell_check>false</spell_check>
<staged>false</staged>
<sys_class_name>sys_dictionary</sys_class_name>
<sys_created_by>asteroid</sys_created_by>
<sys_created_on>2024-10-22 09:29:59</sys_created_on>
<sys_name>Active</sys_name>
<sys_package display_value="SlackerBot" source="x_snc_slackerbot">b02cf9e61b861d10d806dc23b24bcb3f</sys_package>
<sys_policy/>
<sys_scope display_value="SlackerBot">b02cf9e61b861d10d806dc23b24bcb3f</sys_scope>
<sys_update_name>sys_dictionary_x_snc_slackerbot_interaction_active</sys_update_name>
<sys_updated_by>asteroid</sys_updated_by>
<sys_updated_on>2024-10-22 09:29:59</sys_updated_on>
<table_reference>false</table_reference>
<text_index>false</text_index>
<unique>false</unique>
<use_dependent_field>false</use_dependent_field>
<use_dynamic_default>false</use_dynamic_default>
<use_reference_qualifier>simple</use_reference_qualifier>
<virtual>false</virtual>
<virtual_type>script</virtual_type>
<widget/>
<write_roles/>
<xml_view>false</xml_view>
</sys_dictionary>
</record_update>
Loading

0 comments on commit 06cfe5d

Please sign in to comment.