def handle_reaction_added_event( user_email: str, incident_id: int, event: dict = None, db_session=None ): """Handles an event where a reaction is added to a message.""" reaction = event.event.reaction if reaction == SLACK_TIMELINE_EVENT_REACTION: conversation_id = event.event.item.channel message_ts = event.event.item.ts message_ts_utc = datetime.datetime.utcfromtimestamp(float(message_ts)) # we fetch the message information response = dispatch_slack_service.list_conversation_messages( slack_client, conversation_id, latest=message_ts, limit=1, inclusive=1 ) message_text = response["messages"][0]["text"] message_sender_id = response["messages"][0]["user"] # we fetch the individual who sent the message message_sender_email = get_user_email(client=slack_client, user_id=message_sender_id) individual = individual_service.get_by_email( db_session=db_session, email=message_sender_email ) convo_plugin = plugins.get(INCIDENT_PLUGIN_CONVERSATION_SLUG) # we log the event event_service.log( db_session=db_session, source=convo_plugin.title, description=f'"{message_text}," said {individual.name}', incident_id=incident_id, individual_id=individual.id, started_at=message_ts_utc, )
def handle_reaction_added_event( config: SlackConversationConfiguration, user_id: str, user_email: str, channel_id: str, incident_id: int, event: EventEnvelope = None, db_session=None, slack_client=None, ): """Handles an event where a reaction is added to a message.""" reaction = event.event.reaction if reaction == config.timeline_event_reaction: conversation_id = event.event.item.channel message_ts = event.event.item.ts message_ts_utc = datetime.datetime.utcfromtimestamp(float(message_ts)) # we fetch the message information response = dispatch_slack_service.list_conversation_messages( slack_client, conversation_id, latest=message_ts, limit=1, inclusive=1) message_text = response["messages"][0]["text"] message_sender_id = response["messages"][0]["user"] # we fetch the incident incident = incident_service.get(db_session=db_session, incident_id=incident_id) # we fetch the individual who sent the message message_sender_email = get_user_email(client=slack_client, user_id=message_sender_id) individual = individual_service.get_by_email_and_project( db_session=db_session, email=message_sender_email, project_id=incident.project.id) # we log the event event_service.log( db_session=db_session, source="Slack Plugin - Conversation Management", description=f'"{message_text}," said {individual.name}', incident_id=incident_id, individual_id=individual.id, started_at=message_ts_utc, )