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

Configure Feed

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

add open modal action

+34 -34
+1 -1
kefi/constants.py
··· 19 19 20 20 21 21 class Actions: 22 - JOIN_MEET: str = "meet_join" 23 22 LEAVE_MEET: str = "meet_leave" 23 + SHOW_MEETS_MODAL: str = "show_meets_modal"
+32 -31
kefi/routers/helpers.py
··· 200 200 return [] 201 201 202 202 def interaction_block_actions(self) -> list: 203 - actions = self.payload["actions"] 204 - message = self.payload["message"] 205 - channel = self.payload["channel"] 206 - 207 - if actions is not None: 208 - for action in actions: 209 - handler = ActionsHandler( 210 - action=action, 211 - session=self.session, 212 - user=self.user, 213 - message=message, 214 - channel=channel, 215 - ) 216 - handler.handle() 217 - 203 + handler = ActionsHandler( 204 + payload=self.payload, 205 + session=self.session, 206 + user=self.user, 207 + ) 208 + handler.handle() 218 209 return [] 219 210 220 211 def _view_submission_meet_join(self, view_id: str) -> list | dict: ··· 282 273 283 274 284 275 class ActionsHandler: 285 - def __init__( 286 - self, action: dict, channel: dict, message: dict, session: Session, user: User 287 - ): 288 - self.action = action 276 + def __init__(self, session: Session, user: User, payload: dict): 277 + self.payload = payload 289 278 self.session = session 290 - self.message = message 291 - self.channel = channel 292 279 self.user = user 293 280 self.slack = Slack() 294 281 295 - def handle(self) -> SlackResponse: 296 - handlers: dict[str, Callable] = { 297 - Actions.LEAVE_MEET: self.action_leave_meet, 298 - } 299 - response = handlers.get(self.action["action_id"], self.not_found)() 300 - return response 282 + def handle(self): 283 + actions = self.payload.get("actions") 284 + if actions is not None: 285 + for action in actions: 286 + handlers: dict[str, Callable] = { 287 + Actions.LEAVE_MEET: self.action_leave_meet, 288 + Actions.SHOW_MEETS_MODAL: self.action_show_meets_modal, 289 + } 290 + handlers.get(action["action_id"], self.not_found)() 291 + 292 + def not_found(self): 293 + ... 301 294 302 295 def action_leave_meet(self): 303 296 message: BaseMessage ··· 305 298 delete_attendance(user=self.user, session=self.session) 306 299 message = UserLeftMeetMessage() 307 300 self.slack.update_message( 308 - channel=self.channel["id"], 301 + channel=self.payload["channel"]["id"], 309 302 blocks=message.blocks(), 310 303 text=message.text(), 311 - timestamp=self.message["ts"], 304 + timestamp=self.payload["message"]["ts"], 312 305 ) 313 306 except NotAttending: 314 307 message = NotAttendingMessage() ··· 318 311 text=message.text(), 319 312 ) 320 313 321 - def not_found(self): 322 - ... 314 + def action_show_meets_modal(self): 315 + trigger_id = self.payload["trigger_id"] 316 + if not is_attending(user=self.user, session=self.session): 317 + self.slack.open_view( 318 + trigger_id=trigger_id, view=JoinMeetView(session=self.session) 319 + ) 320 + else: 321 + self.slack.open_view( 322 + trigger_id=trigger_id, view=LeaveMeetView(session=self.session) 323 + )
+1 -2
kefi/routers/views.py
··· 91 91 def __init__(self, *args, **kwargs): 92 92 super().__init__( 93 93 type="home", 94 - # TODO: not needed: submit=PlainTextObject(text="No asistiré"), 95 94 blocks=[ 96 95 HeaderBlock( 97 96 text=PlainTextObject(text="Esto es lo que puedes hacer con Kefi:") ··· 152 151 elements=[ 153 152 ButtonElement( 154 153 text=PlainTextObject(text="¡Me Apunto!"), 155 - action_id=Actions.JOIN_MEET, 154 + action_id=Actions.SHOW_MEETS_MODAL, 156 155 ) 157 156 ] 158 157 ),