Python backend for a Slack's kudos plugin.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat(feedback): add feedback messages

+76 -8
+4
kefi/constants.py
··· 16 16 class ViewType: 17 17 JOIN_MEET: str = "meet_join" 18 18 LEAVE_MEET: str = "meet_leave" 19 + 20 + 21 + class Actions: 22 + LEAVE_MEET: str = "meet_leave"
+15 -7
kefi/routers/helpers.py
··· 27 27 delete_attendance, 28 28 is_attending, 29 29 ) 30 + from kefi.routers.messages import UserJoinedMeet, UserLeftMeet 30 31 from kefi.routers.responses import ( 31 32 ActionResponse, 32 33 HelpResponse, ··· 193 194 def interaction_block_actions(self) -> list: 194 195 return [] 195 196 196 - def _view_submission_meet_join(self, view_id: str) -> list | dict: 197 + def _view_submission_meet_join(self, view_id: str, user_id: str) -> list | dict: 197 198 """Joins the plaza.""" 198 199 try: 199 200 create_attendance(user=self.user, session=self.session) 200 - return {"response_action": "clear"} 201 + self.slack.post_message_user( 202 + user_id=user_id, 203 + blocks=UserJoinedMeet.blocks(), 204 + text=UserJoinedMeet.text(), 205 + ) 201 206 except NotEnoughKefi: 202 207 ... 203 208 except AlreadyAttending: 204 209 ... 205 - return [] 210 + return {"response_action": "clear"} 206 211 207 - def _view_submission_meet_leave(self, view_id: str) -> list | dict: 212 + def _view_submission_meet_leave(self, view_id: str, user_id: str) -> list | dict: 208 213 """Leaves the plaza.""" 209 214 try: 210 215 delete_attendance(user=self.user, session=self.session) 211 - return {"response_action": "clear"} 216 + self.slack.post_message_user( 217 + user_id=user_id, blocks=UserLeftMeet.blocks(), text=UserLeftMeet.text() 218 + ) 212 219 except NotAttending: 213 220 ... 214 - return [] 221 + return {"response_action": "clear"} 215 222 216 223 def interaction_view_submission(self) -> list | dict: 217 224 """Handles the submissions from a view.""" 218 225 view_id = self.payload["view"]["id"] 226 + user_id = self.payload["user"]["id"] 219 227 view_callback_id = self.payload["view"]["callback_id"] 220 228 try: 221 229 return getattr(self, f"_view_submission_{view_callback_id}")( 222 - view_id=view_id 230 + view_id=view_id, user_id=user_id 223 231 ) 224 232 except AttributeError: 225 233 ...
+53
kefi/routers/messages.py
··· 1 + from slack_sdk.models.blocks import ( 2 + Block, 3 + ButtonElement, 4 + ContextBlock, 5 + DividerBlock, 6 + ImageElement, 7 + MarkdownTextObject, 8 + PlainTextObject, 9 + SectionBlock, 10 + ) 11 + 12 + from kefi.constants import Actions 13 + 14 + 15 + class UserJoinedMeet: 16 + @staticmethod 17 + def text() -> str: 18 + return ":tada: ¡Genial! ¡Nos vemos el próximo viernes!" 19 + 20 + @staticmethod 21 + def blocks() -> list[Block]: 22 + return [ 23 + SectionBlock( 24 + text=MarkdownTextObject( 25 + text=":tada: ¡Genial! ¡Nos vemos el próximo viernes!" 26 + ) 27 + ), 28 + DividerBlock(), 29 + SectionBlock( 30 + text=MarkdownTextObject(text="¿Cambio de planes?"), 31 + accessory=ButtonElement( 32 + text=PlainTextObject(text="No asistiré"), 33 + style="danger", 34 + action_id=Actions.LEAVE_MEET, 35 + ), 36 + ), 37 + ] 38 + 39 + 40 + class UserLeftMeet: 41 + @staticmethod 42 + def text() -> str: 43 + return ":disappointed: ¡Vaya! ¡Esperamos verte la próxima vez!" 44 + 45 + @staticmethod 46 + def blocks() -> list[Block]: 47 + return [ 48 + SectionBlock( 49 + text=MarkdownTextObject( 50 + text=":disappointed: ¡Vaya! ¡Esperamos verte la próxima vez!" 51 + ) 52 + ), 53 + ]
+2
kefi/routers/responses.py
··· 1 + from slack_sdk.models.blocks import Block 2 + 1 3 from kefi.models.database import Action, User 2 4 from kefi.models.outputs import ( 3 5 Context,
+2 -1
kefi/slack.py
··· 1 1 import uuid 2 2 from collections.abc import Sequence 3 3 4 + from slack_sdk.models.blocks import Block 4 5 from slack_sdk.models.views import View 5 6 from slack_sdk.web.client import WebClient 6 7 ··· 42 43 return user_chats 43 44 44 45 def post_message_user( 45 - self, user_id: str, blocks: Sequence[dict], text: str | None = None 46 + self, user_id: str, blocks: Sequence[dict | Block], text: str | None = None 46 47 ): 47 48 self.client.chat_postMessage(channel=user_id, blocks=blocks, text=text) 48 49