Ich versuche derzeit, einen benutzerdefinierten Slack Bot in einen meiner Kanäle zu integrieren. Allerdings habe ich ein Problem, bei dem der Bot nicht als der benutzerdefinierte Bot-Benutzer, sondern eher als ich posten wird.Custom Slack Bot nicht als Benutzer
Der Bot reagiert auf meine benutzerdefinierten Befehle und Zeug, aber aus irgendeinem Grunde Posting nicht als Bot, die ich einrichten. Ich verwende das API-Token, das mir beim Einrichten des Bots zugewiesen wurde, und fügte es dem Kanal hinzu, in dem ich gerade teste. Wer weiß, was dieses Problem verursachen könnte?
Relevante Code:
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
wurde mit der API und die gegebenen Token initialisiert und AT_BOT
ist nur eine Konstante für das Zeichen '@' und den Namen meines bietet.
zeigen uns der Code – depperm
entsprechende Code hinzugefügt, sorry – AJwr