-
Notifications
You must be signed in to change notification settings - Fork 839
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Build a Slack app using message event subscription #1157
Comments
This part is not correct. The key should be “channel”, not “chanel”. |
Oh thank you very much can't belive I missed that, I had another issue with slack api, this is more of a logic issue: I have the following code: Hello Everyone, client = slack.WebClient(token=os.getenv("SLACK_TOKEN"))
BOT_ID = client.api_call("auth.test")['user_id']
@slack_event_adapter.on('message')
def message(payload):
event = payload.get('event', {})
channel_id = event.get('channel')
user_id = event.get('user')
text = event.get('text')
today = date.today()
d4 = today.strftime("%Y-%m-%d")
print(d4)
tickerWant = text
data = yf.download(tickerWant, start="2021-09-5", end=d4)
data.to_csv(rf'C:\work\demo\data\{tickerWant}.csv')
# if BOT_ID != user_id:
# client.chat_postMessage(channel=channel_id, text = 'print succesful') so at first the code after tickerWant was in a different file, my understanding was that I could do from chart import message(chart.py is the main python that I had defined message into) that didn't work as I didn't know what to put in the payload argument. I have this code now in the main py file. The issue I am having currently is that once I get the csv file printed to my local storage, I want my code to post successful print to the slack message channel. As of now, it will only do that once I kill the program and if I use client.chat_postMessage() without the if statement with the botID then I repeatedly get the issue of me getting print successful in succession to my slack channel, I dont want that I only want it once its printed. This is an logic error that I don't know how to solve any help would be appreciated. |
Your app might not be responding to requests from Slack within 3 seconds. If so, that can be one of the reasons that your app prints several times. In this scenario, your app receives the same request three times at maximum. For this reason, python-slack-events-api is not recommended for complex apps. Refer to slackapi/python-slack-events-api#84 (comment) for more details. Instead, we recommend using bolt-python; with this library, running time-consuming code in your listener is much easier. You can find many examples here: https://github.com/slackapi/bolt-python/tree/main/examples
If you go with bolt-python, this if statement is no longer necessary. bolt-python framework automatically ignores the app itself's events for you. I think that I've answered all your questions here. Would you mind closing this issue now? Also, if you continue your app development with bolt-python, please feel free to ask questions here: https://github.com/slackapi/bolt-python/issues/new/choose |
thank you |
Hi, I have similar code but it is correct. I can't connect my ngrok to flask, but it connects to the url request in slack api website. |
I was basically following video tutorial: https://www.youtube.com/watch?v=6gHvqXrfjuo&t=1030s
everything was working but until I started getting this error.
Following is the code:
The text was updated successfully, but these errors were encountered: