def run(self):
# create one at https://api.slack.com/web#authentication, and set the environment variable
sc = SlackClient(os.environ["SLACK_CLIENT_TOKEN"])
channel_id = 0
# Get Channel Information
for channel in sc.api_call("channels.list")["channels"]:
if (channel["name"] == self.channel_name):
channel_id = channel["id"]
# Get Channel History
if (self.last_message_id):
channel_history_chunk = sc.api_call("channels.history", channel=channel_id, count=1000, latest=self.last_message_id)
else:
channel_history_chunk = sc.api_call("channels.history", channel=channel_id, count=1000)
if (not channel_history_chunk["ok"]):
raise Exception('Channel not found, or permissions error', 'channel_name=' + self.channel_name)
channel_history_chunk_last_message = channel_history_chunk["messages"]
outputdata = channel_history_chunk
with self.output().open('w') as outfile:
json.dump(outputdata, outfile, sort_keys=True, indent=4, separators=(',', ': '))
评论列表
文章目录