slkmsg.py 文件源码

python
阅读 17 收藏 0 点赞 0 评论 0

项目:sci-pype 作者: jay-johnson 项目源码 文件源码
def post_message_to_slack(self, channel, message, debug=False):

        slack_response  = {}

        try:

            # SlackHQ Repository for integrating with the Slack API:
            # https://github.com/slackhq/python-slackclient         
            import slackclient

            slack = slackclient.SlackClient(self.m_slack_token)

            slack_response = slack.api_call("chat.postMessage", channel=channel, text=message, username=self.m_bot_name, as_user=True)

            if "error" in slack_response:
                print "\nERROR: Slack API call had an error(" + str(slack_response["error"]) + ")\n"

        except Exception, e:
            err_msg = "Failed to post message to slack with Ex(" + str(e) + ") SlackResponse(" + str(slack_response) + ")"
            print "ERROR: " + str(err_msg)
        # end of try/ex

    # end of post_message_to_slack


# end of SlkMsg
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号