我目前正在嘗試將自定義Slack bot整合到我的一個頻道中。但是,我遇到了一個問題,即bot不是作爲自定義bot用戶發佈的,而是作爲我發佈的。自定義Slack Bot不以用戶身份發帖
殭屍迴應我的自定義命令和東西,但出於某種原因沒有公佈爲我設置的機器人。我正在使用設置機器人時向我提供的API令牌,並將其添加到我正在測試的通道中。任何人都知道可能會導致此問題的原因?
相關代碼:
def handle_command(command, channel):
"""Receives commands directed at the bot and determines if they are valid commands. If so,
then acts on the commands. If not, returns back what it needs for clarification.
"""
response = "Hello there!"
if command.startswith("yes"):
response = "You posted 'yes'!"
SLACK_CLIENT.api_call("chat.postMessage", channel=channel,
text=response, as_user=True)
def parse_slack_output(slack_rtm_output):
"""The Slack Real Time Messaging API is an events firehose. This parsing function returns
None unless a message is directed at the Bot, based on its ID.
"""
output_list = slack_rtm_output
if output_list and len(output_list) > 0:
for output in output_list:
if output and 'text' in output and AT_BOT in output['text']:
# return text after the @ mention, whitespace removed
return output['text'].split(AT_BOT)[1].strip().lower(), \
output['channel']
return None, None
def main():
"""Obtains Google Credentials to rotate and update a Google Spreadsheet that keeps track of the
current engineer with 10 percent time. Notifies the engeineering team through a Google Calendar
event.
"""
if SLACK_CLIENT.rtm_connect():
print "Bot connected and running."
while True:
command, channel = parse_slack_output(SLACK_CLIENT.rtm_read())
if command and channel:
handle_command(command, channel)
time.sleep(1)
else:
print "Connection failed."
SLACK_CLIENT
使用API和給定的令牌初始化,並且是隻爲「@」字符和我的機器人的名字不變。
告訴我們添加的代碼 – depperm
相關的代碼,對不起 – AJwr