Closed rkbala closed 5 years ago
@aoberoi I see the issue with v1.3.0 as well... Bot is not recognizing the commands once the Bot is up.
@rkbala we will need some more information to help you. there were no (intentional) breaking changes in any 1.x version. What version were you upgrading from? Can you provide a minimal code example (please don't show us all the code in your bot, just ~20 lines if possible) of something you think should work but is not working?
I guess the issue is not with version. I was using my bot with 1.0.9. But now I upgraded to 1.3.0 in local and trying. STill I could not get any response. I see the Bot is getting connected and running. But I when I pass commands from slack, It is not responding.
Am using code from https://www.fullstackpython.com/blog/build-first-slack-bot-python.html
What do you mean by "pass commands from slack"? Does this mean when you send a @StarterBot do xyz
message into channel, the bot is not responding? Do you seen any logs on the terminal where the bot is running? Which Python version are you running?
@aoberoi I got the response after 2 minutes for the command. When I try the same again, app is not getting connected to RTM API I guess. I just did print(slack_events) and could see lot of other events happening. I am not sure if this is causing the delay and my bot could not listen to my command.
@aoberoi Yes I meant @StarterBot do xyz. I am using Python 3.5.2 version. I am trying in windows. I am running the code in my local desktop. The terminal is not showing any error. Thats the weird part :(
okay there are some general debugging steps you can take.
1) Verify that the bot is actually in the channel where you are sending the message. I've made this simple mistake before, and it felt embarassing when I found it was just this simple 😆.
2) Add some logging statements to understand which parts of your app are working as expected. For the tutorial code, I have a few suggestions:
a) After the `starterbot_id = slack_client.api_call("auth.test")["user_id"]` statement, try to `print(starterbot_id)`. If you see this value on the console, then you at least know this part is working.
b) In `parse_bot_commands()`, before the `user_id, message = parse_direct_mention(event["text"])` statement, add `print(event)`. Now each time you send a message into the channel, you should see that message printed to the terminal. It shouldn't matter if the bot is mentioned or not.
Let me know what happens after that.
I did try print slack bot I’d and it printed. Also I have printed slack_event and it printed other events... but not the “do”... I haven’t tried print(event)... will let you know... I felt like it did not even going inside the for loop in parse_bot_commands method...
@aoberoi like I said, its not entering into for loop at all... Not sure why...
if event["type"] == "message" and not "subtype" in event:
print(event)
Its not printing anything. Started_bot_id is being prnted correcty. Also I am directly pinging BOT. I am not pinging in channel.
Also I am directly pinging BOT. I am not pinging in channel.
This is not how the tutorial is meant to work. Can you try to use a channel?
PS. I asked what was on the terminal and you said nothing but then later you said you already printed the bot ID. Now you're also telling me you're not using a channel. These differences are important and knowing would save me time in helping you. 🙏
@aoberoi It went once and gave the response after 2 minutes. Then i triggered the command again. But the bot lost connectivity and it did not throw any exception in my terminal...God...am not sure whats happening here?
@aoberoi same issue when I trigger the message via channel as well.
Terminal is not showing any error. But I could see the Bot "green light" (online indicator) being disappeared after triggering the command second time.
Terminal just says "Starter Bot connected and running!" and the Bot ID thats being printed.
gave the response after 2 minutes
this sounds like your bot might be very busy. there can be a few reasons for this, and here are the most common:
slack_client.rtm_connect(with_team_state=False)
includes the very important with_team_state=False
option which can eliminate this problem.RTM_READ_DELAY
smaller. instead of 1
, you can try 0.5
. if you cannot reduce the number of channels and decreasing the delay doesn't help, then I suggest you create a new app with a new bot user, so that this bot is not in all the other places the previous token might be getting used.I could see the Bot "green light" (online indicator) being disappeared after triggering the command second time
This sounds like the program is crashing. Does the indicator come back on its own, without restarting the program?
It sounds like you might be reusing a bot token that some other programs are using, and maybe this is why the presence state is confusing.
@aoberoi No, the indicator does not come back on its own. Am not sure how come it got busy just from today.
When I do print(slack_events). It prints lot of events with type': 'file_deleted'. I am not sure if this is common. Probably this is causing the delay for bot to identify the appropriate event?
No, Only I am using this Bot token.
even I tried after regenerating the token, Still the same...
@aoberoi I reduced the time delay and its very fast now. RTM_READ_DELAY = 0.0001.
Bot is responding very fast.
Is there gonna be impact due to this change?
No, the indicator does not come back on its own.
Okay, so the program ends without showing you a crashing error? Or, the program continues running even though the indicator shows the bot is offline?
Tt prints lot of events with type': 'file_deleted'. I am not sure if this is common. Probably this is causing the delay for bot to identify the appropriate event?
It sounds like either another user or another app in your workspaces is mass deleting many files. Typically, these kinds of apps are not good for the health of your workspace for reasons like this. I understand that many people use apps like this to stay within the free tier pricing plan, but this is a negative effect of trying to game the pricing - you should consider upgrading or adjusting you usage to stay in the free tier without such apps.
RTM_READ_DELAY = 0.0001
There is a cost on the CPU running the bot. The lower this number, the more CPU time your app will take on the machine, even when there is no activity in the team. Generally, hosting providers charge you money for CPU time.
Returning multiple events from each call to rtm_read()
should also help reduce this busy problem - it would allow your app to more quickly discard the events it didn't care about. (Ref #277)
I think we've solved this issue. The bot is very busy because of the activity in the team and all the events its seeing, so its very slow to handle incoming messages.
Besides the strategies we've already discussed, my most important recommendation is to explore using the Events API instead of using RTM. The Events API allows you to subscribe to only the events your app cares about, so this problem would not happen. Check out https://github.com/slackapi/python-slack-events-api for a tool to do this in Python.
Description
Describe your issue here.
What type of issue is this? (place an
x
in one of the[ ]
)Requirements (place an
x
in each of the[ ]
)Bug Report
Filling out the following details about bugs will help us solve your issue sooner.
Reproducible in:
slackclient version:
python version:
OS version(s):
Steps to reproduce:
1. 2. 3.
Expected result:
What you expected to happen
Actual result:
What actually happened
Attachments:
Logs, screenshots, screencast, sample project, funny gif, etc.