def process_incoming_slack(body): data = json.loads(body) if 'challenge' in data: return { "statusCode": 200, "headers": { "Content-Type": "text/plain", }, "body": str(data['challenge']) } incoming_slack_message_id, slack_message, channel, is_person = parse_message( data) if incoming_slack_message_id and slack_message: destination = get_to_destination(incoming_slack_message_id, channel) formatted_body = emoji_data_python.replace_colons(slack_message) if destination and destination['type'] == 'phone_number': twilio_client.messages.create(to=destination['number'], from_=twilio_number, body=formatted_body) elif is_person and destination and destination[ 'type'] == 'email_address': to_address = destination['address'] subject = 'Re: ' + destination['subject'] send_email(email_account, to_address, subject, formatted_body) return {"statusCode": 200} return {"statusCode": 200}
def test_multiline_sentence(self): self.assertEqual( """ Hello 👋 world 🌍 ! How are you ❓""", replace_colons(""" Hello :wave: world :earth_africa: ! How are you :question:"""))
def unslackify(value): """Takes a string and turns slack style :emoji: into unicode""" value = slack_to_human_readable(value) # replace all colon style :emoji: with unicode value = emoji_data_python.replace_colons(value) return value
def get_details_ui(self, instance): details_ui = slack_to_human_readable(instance.details) details_ui = emoji_data_python.replace_colons(details_ui) return details_ui
def get_text_ui(self, instance): text_ui = slack_to_human_readable(instance.text) text_ui = emoji_data_python.replace_colons(text_ui) return text_ui
def test_replace_colons(self): self.assertEqual('😄', replace_colons(':smile:')) self.assertEqual('😗', replace_colons(':kissing:'))
def test_strip_unknown_code(self): self.assertEqual( '💩💩 🏼', replace_colons(':hankey::poop: :poo::skin-tone-3:', strip=True))
def test_unknown_code(self): self.assertEqual('💩💩 :poo:🏼', replace_colons(':hankey::poop: :poo::skin-tone-3:'))
def test_zwj_emoji(self): """These emoji are joined by a Zero Width Joiner""" self.assertEqual('👨👩👦', replace_colons(':man-woman-boy:')) self.assertEqual('👨🌾', replace_colons(':male-farmer:'))
def test_main_shortname_precedence(self): """There are two emoji for the family shortcode, one as the main short_name and one in the short_names_list""" self.assertEqual('👪', replace_colons(':family:'))
def test_underscore_hyphenated_codes(self): self.assertEqual('😙', replace_colons(':kissing_smiling_eyes:')) self.assertEqual('😘', replace_colons(':kissing-heart:'))
def test_skin_tone(self): self.assertEqual('👋🏼', replace_colons(':wave::skin-tone-3:'))