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

Configure Feed

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

edit message

+48 -9
+35 -6
kefi/routers/helpers.py
··· 201 201 202 202 def interaction_block_actions(self) -> list: 203 203 actions = self.payload["actions"] 204 + message = self.payload["message"] 205 + channel = self.payload["channel"] 206 + 204 207 if actions is not None: 205 208 for action in actions: 206 - ActionsHandler(action=action, session=self.session, user=self.user) 209 + handler = ActionsHandler( 210 + action=action, 211 + session=self.session, 212 + user=self.user, 213 + message=message, 214 + channel=channel, 215 + ) 216 + handler.handle() 207 217 208 218 return [] 209 219 ··· 272 282 273 283 274 284 class ActionsHandler: 275 - def __init__(self, action: dict, session: Session, user: User): 285 + def __init__( 286 + self, action: dict, channel: dict, message: dict, session: Session, user: User 287 + ): 276 288 self.action = action 277 289 self.session = session 290 + self.message = message 291 + self.channel = channel 278 292 self.user = user 279 293 self.slack = Slack() 280 294 281 - def response(self) -> SlackResponse: 295 + def handle(self) -> SlackResponse: 282 296 handlers: dict[str, Callable] = { 283 297 Actions.LEAVE_MEET: self.action_leave_meet, 284 298 } 285 - action_id = self.action["action_id"] 286 - response = handlers.get(action_id, self.not_found)() 299 + response = handlers.get(self.action["action_id"], self.not_found)() 287 300 return response 288 301 289 302 def action_leave_meet(self): 290 - ... 303 + message: BaseMessage 304 + try: 305 + delete_attendance(user=self.user, session=self.session) 306 + message = UserLeftMeetMessage() 307 + self.slack.update_message( 308 + channel=self.channel["id"], 309 + blocks=message.blocks(), 310 + text=message.text(), 311 + timestamp=self.message["ts"], 312 + ) 313 + except NotAttending: 314 + message = NotAttendingMessage() 315 + self.slack.post_message_user( 316 + user_id=self.user.slack_user_id, 317 + blocks=message.blocks(), 318 + text=message.text(), 319 + ) 291 320 292 321 def not_found(self): 293 322 ...
-1
kefi/routers/interactivity.py
··· 14 14 ): 15 15 """Calls the interaction handler and gets the response.""" 16 16 interaction_handler = InteractionHandler(interaction=interaction, session=session) 17 - print(interaction.payload) 18 17 return interaction_handler.response()
+4 -2
kefi/routers/messages.py
··· 75 75 76 76 class NotAttendingMessage(BaseMessage): 77 77 def text(self) -> str: 78 - return "" 78 + return "Test" 79 79 80 80 def blocks(self) -> list[Block]: 81 - return [] 81 + return [ 82 + SectionBlock(text=MarkdownTextObject(text="Test")), 83 + ]
+9
kefi/slack.py
··· 47 47 ): 48 48 self.client.chat_postMessage(channel=user_id, blocks=blocks, text=text) 49 49 50 + def update_message( 51 + self, 52 + channel: str, 53 + timestamp: str, 54 + blocks: Sequence[dict | Block], 55 + text: str | None = None, 56 + ): 57 + self.client.chat_update(channel=channel, blocks=blocks, text=text, ts=timestamp) 58 + 50 59 def open_view(self, trigger_id: str, view: View): 51 60 self.client.views_open(trigger_id=trigger_id, view=view) 52 61