forked from slackapi/Slack-Python-Onboarding-Tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
message.py
37 lines (34 loc) · 1.28 KB
/
message.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# -*- coding: utf-8 -*-
"""
Python Slack Message class for use with the pythOnBoarding bot
"""
# TODO: Fix hack with yaml library for handling unicode encoding issues
import yaml
class Message(object):
"""
Instantiates a Message object to create and manage
Slack onboarding messages.
"""
def __init__(self):
super(Message, self).__init__()
self.channel = ""
self.timestamp = ""
self.text = ("Welcome to Slack! We're so glad you're here. "
"\nGet started by completing the steps below.")
self.emoji_attachment = {}
self.pin_attachment = {}
self.share_attachment = {}
self.attachments = [self.emoji_attachment,
self.pin_attachment,
self.share_attachment]
def create_attachments(self):
"""
Open JSON message attachments file and create attachments for
onboarding message. Saves a dictionary of formatted attachments on
the bot object.
"""
with open('welcome.json') as json_file:
json_dict = yaml.safe_load(json_file)
json_attachments = json_dict["attachments"]
[self.attachments[i].update(json_attachments[i]) for i
in range(len(json_attachments))]