def thank(): sender_id = request.form.get('user_id') message = request.form.get('text') space_bar_index = message.find(' ') recipient_name = message[1:space_bar_index] message = message[space_bar_index + 1:] recipient_profile = next(prof for prof in list(profiles_dict.values()) if prof.slack_internal_name == recipient_name) thanks.append(Thank(profiles_dict[sender_id], recipient_profile, message)) slackbot.send_dm_to_user( recipient_profile.id, "<@{}> just thanked you for {}!".format(profiles_dict[sender_id].id, message)) return { "blocks": [{ "type": "section", "text": { "type": "mrkdwn", "text": "Love the positivity! Checkout https://thehub.com to see who's thanked you!" } }] }
def message(payload): event = payload.get("event", {}) if 'bot_id' in event: return make_boolean_response() channel_id = event.get("channel") user_id = event.get("user") last_messages = slackbot.messages_in_channel(channel_id, 2) last_bot_question = next(msg for msg in last_messages if 'bot_id' in msg) answer = event['text'] if last_bot_question['text'] == onboarding_questions[0]: profiles_dict[user_id].blurb = answer slackbot.send_dm_to_user(user_id, onboarding_questions[1]) elif last_bot_question['text'] == onboarding_questions[1]: interests = answer.split(',') profiles_dict[user_id].interests = [ interest.strip() for interest in interests ] elif last_bot_question['text'] in daily_questions: profiles_dict[user_id].daily_questions.append( DailyQuestion(last_bot_question['text'], answer)) slackbot.send_dm_to_user(user_id, daily_q_confirmation) elif last_bot_question['blocks'][0]['block_id'] in all_polls: poll = all_polls[last_bot_question['blocks'][0]['block_id']] poll.add_vote(answer, user_id) slackbot.send_dm_to_user(user_id, poll_confirmation)
def reaction_added(payload): event = payload.get("event", {}) user_id = event.get("user") slackbot.send_dm_to_user(user_id, "Welcome!") slackbot.send_dm_to_user(user_id, onboarding_questions[0])
def send_message(): user_id = request.json['user_id'] message = request.json['message'] slackbot.send_dm_to_user(user_id, message) return make_boolean_response()
import slackbot from init_profiles import init_profiles user_list = list(init_profiles().keys()) daily_questions = [ 'What is your favorite TV Show?', 'Who is your favorite music artist?', 'What have you learned during quarantine?', ] if __name__ == '__main__': for user_id in user_list: slackbot.send_dm_to_user(user_id, daily_questions[0]) daily_questions.append(daily_questions.pop(0))