我目前正在尝试将自定义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