Skip to content
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

Messages are received four times #75

Closed
alexattia opened this issue Sep 10, 2020 · 12 comments
Closed

Messages are received four times #75

alexattia opened this issue Sep 10, 2020 · 12 comments
Labels
question Further information is requested

Comments

@alexattia
Copy link

Hello,

I have a similar error I had with the regular slack client : cf issue .

I switched to bolt in order to solve this issue and it was working for a couple of days but now I received the same message three to four times each time.

When I look at the logs, I have this for the same message:

{'client_msg_id': '59c755aa-80cf-4a77-8852-6073f776ca07', 'type': 'message', 'text': 'HPSM,.', 'user': 'U7PDK2W1J', 'ts': '1599757663.004700', 'team': 'T7P9RQX35', 'blocks': [{'type': 'rich_text', 'block_id': 'YhMu', 'elements': [{'type': 'rich_text_section', 'elements': [{'type': 'text', 'text': 'MESSAGE'}]}]}], 'channel': 'D8X4RT3PW', 'event_ts': '1599757663.004700', 'channel_type': 'im'}

{'client_msg_id': 'eece3ee7-2dab-4585-8bef-6be776645e80', 'type': 'message', 'text': 'HPSM,.', 'user': 'U7PDK2W1J', 'ts': '1599757626.004100', 'team': 'T7P9RQX35', 'blocks': [{'type': 'rich_text', 'block_id': 'oH4=p', 'elements': [{'type': 'rich_text_section', 'elements': [{'type': 'text', 'text': 'HPSM,.'}]}]}], 'channel': 'D8X4RT3PW', 'event_ts': '1599757626.004100', 'channel_type': 'im'}

(etc.)

And when I look at the IP sent, there are different.

Thank you in advance.

@misscoded
Copy link
Contributor

Hi @alexattia! Sorry to hear you've bumped up against the same issue. Let's see if we can get it sorted.

Can you provide similar information as you did in the cf issue you've referenced -- specifically, the Steps to reproduce/code snippet?

@misscoded misscoded added the question Further information is requested label Sep 10, 2020
@alexattia
Copy link
Author

alexattia commented Sep 14, 2020

Of course. Thank you in advance

Reproducible in:

slack-bolt==0.4.0a0
slack-sdk==3.0.0a4
slackclient==2.8.2
slackeventsapi==2.2.1

Python 3.6.12

#108~16.04.1-Ubuntu

Steps to reproduce:

from slack_bolt import App
app = App()

def handle_command(message, say)
    say(message)

@app.event("message")
def parse_bot_commands(payload, say):
    if payload["type"] == "message" and not "subtype" in payload :
        print(Message received, payload)
        message = payload["text"].lower()
        if 'hello' in message.lower():
            say("Hello you")
        elif "bye" in message.lower():
           handle_command("Bye", say)
            

if __name__ == "__main__":
    print("Starter Bot connected and running!")
    app.start(port=3000)

Expected result:

I am sending a message to the bot and I am supposed to receive one answer.

Actual result:

I received 4 times the same answer (3 times in a row and 6 minutes later a fourth time). If I send two different messages, I received two different answers (but with still 3 times for each answer)

@seratch
Copy link
Member

seratch commented Sep 14, 2020

@alexattia Thanks for sharing this! However, it seems the code in Steps to reproduce: doesn't work. It looks like a mix of a Bolt app and a Flask app. Also, the handle_command method looks unused.
Regarding the version of slack_bolt, just in case, try the lastest alpha version 🙇 There are no changes related to your issue though: v0.4.0a0...v0.5.2a0

@alexattia
Copy link
Author

Sorry for the mistakes in the code. I just edited it.
Alright, I am updating it to the latest version and let you know

@seratch
Copy link
Member

seratch commented Sep 16, 2020

@alexattia I tried your code and it doesn't successfully handle requests.

127.0.0.1 - - [16/Sep/2020 08:53:44] "POST /slack/events HTTP/1.1" 200 -
ERROR:slack_bolt.App:Failed to run listener function (error: name 'event' is not defined)
Traceback (most recent call last):
  File "/Users/ksera/github/bolt-python/slack_bolt/app/app.py", line 322, in run_ack_function_asynchronously
    listener.run_ack_function(request=request, response=response)
  File "/Users/ksera/github/bolt-python/slack_bolt/listener/custom_listener.py", line 46, in run_ack_function
    return self.ack_function(
  File "samples/events_app.py", line 28, in parse_bot_commands
    if payload["type"] == "message" and not "subtype" in event:

I found that, in this case, the current implementation of Bolt for Python returns either 200 OK or 404 Not Found. It depends on the timing the exception is raised. If the app returns 404 to Slack, Slack retries the same request. Can you check if your app is working as you expect?

I will be changing this behavior to avoid confusion in the next patch version. Thanks for sharing this pattern.

@seratch
Copy link
Member

seratch commented Sep 16, 2020

@alexattia I just released a new alpha version including the fix for 404 errors I mentioned above: v0.5.2a0...v0.5.3a0

Please run pip install slack_bolt==0.5.3a0 and make sure how your app works.

If you still receive retried events, it may not be an issue on the API client-side. In the case, I'm sorry for bothering you but please contact our developer support agent team: https://my.slack.com/help/requests/new The team helps you out by deeper investigations with your app/workspace information and its server-side logs.

@alexattia
Copy link
Author

alexattia commented Sep 16, 2020

Sorry for the mistake, event was from the complex code. I just edited the simplified version and added a print for logs.

Alright, I am testing with the update. I will keep you updated

However, with v0.5.2a0, I still received retried events as shown in these logs :

Message receveid. {'client_msg_id': 'aea32b9f-4985-4b8e-b781-f6e3c2ea7ba8', 'type': 'message', 'text': MESSAGE, 'user': XXX, 'ts': '1600245828.000200', 'team': 'T7P9RQX35', 'blocks': [{'type': 'rich_text', 'block_id': 'kaWKq', 'elements': [{'type': 'rich_text_section', 'elements': [{'type': 'text', 'text': MESSAGE}]}]}], 'channel': 'D8X4RT3PW', 'event_ts': '1600245828.000200', 'channel_type': 'im'}
18.212.93.51 - - [16/Sep/2020 10:43:57] "POST /slack/events HTTP/1.1" 200 -
Message receveid. {'client_msg_id': 'aea32b9f-4985-4b8e-b781-f6e3c2ea7ba8', 'type': 'message', 'text': MESSAGE, 'user': XXX, 'ts': '1600245828.000200', 'team': 'T7P9RQX35', 'blocks': [{'type': 'rich_text', 'block_id': 'kaWKq', 'elements': [{'type': 'rich_text_section', 'elements': [{'type': 'text', 'text': MESSAGE}]}]}], 'channel': 'D8X4RT3PW', 'event_ts': '1600245828.000200', 'channel_type': 'im'}
3.89.251.7 - - [16/Sep/2020 10:44:05] "POST /slack/events HTTP/1.1" 200 -
54.152.202.110 - - [16/Sep/2020 10:44:19] "POST /slack/events HTTP/1.1" 200 -
54.175.56.24 - - [16/Sep/2020 10:44:27] "POST /slack/events HTTP/1.1" 200 -
52.23.240.52 - - [16/Sep/2020 10:44:35] "POST /slack/events HTTP/1.1" 200 -
3.84.163.222 - - [16/Sep/2020 10:44:43] "POST /slack/events HTTP/1.1" 200 -
Message receveid. {'client_msg_id': 'aea32b9f-4985-4b8e-b781-f6e3c2ea7ba8', 'type': 'message', 'text': MESSAGE, 'user': XXX, 'ts': '1600245828.000200', 'team': 'T7P9RQX35', 'blocks': [{'type': 'rich_text', 'block_id': 'kaWKq', 'elements': [{'type': 'rich_text_section', 'elements': [{'type': 'text', 'text': MESSAGE}]}]}], 'channel': 'D8X4RT3PW', 'event_ts': '1600245828.000200', 'channel_type': 'im'}
54.86.173.88 - - [16/Sep/2020 10:45:02] "POST /slack/events HTTP/1.1" 200 -
3.89.251.7 - - [16/Sep/2020 10:45:23] "POST /slack/events HTTP/1.1" 200 -
3.89.251.7 - - [16/Sep/2020 10:45:32] "POST /slack/events HTTP/1.1" 200 -
54.158.9.85 - - [16/Sep/2020 10:45:40] "POST /slack/events HTTP/1.1" 200 -
52.23.161.2 - - [16/Sep/2020 10:45:48] "POST /slack/events HTTP/1.1" 200 -

@seratch
Copy link
Member

seratch commented Sep 16, 2020

@alexattia Hmm, it seems your app always returns 200 OK. Would you mind contacting our support team as I mentioned above? We, Slack SDK maintainers, are unable to help you out by accessing your app/workspace information as this issue tracker is a public place.

@alexattia
Copy link
Author

alexattia commented Sep 16, 2020

Indeed, with the update, I still have this

Starter Bot connected and running!
 ⚡️ Bolt app is running! (development server)
54.175.56.24 - - [16/Sep/2020 10:56:32] "POST /slack/events HTTP/1.1" 200 -
Message receveid. {'client_msg_id': '369b527f-f72c-4ff1-a8ab-4f5fcdd7b5e0', 'type': 'message', 'text': MESSAGE, 'user': USER, 'ts': '1600246829.001100', 'team': 'T7P9RQX35', 'blocks': [{'type': 'rich_text', 'block_id': 'jg=NL', 'elements': [{'type': 'rich_text_section', 'elements': [{'type': 'text', 'text': MESSAGE}]}]}], 'channel': 'D8X4RT3PW', 'event_ts': '1600246829.001100', 'channel_type': 'im'}
54.152.202.110 - - [16/Sep/2020 11:00:38] "POST /slack/events HTTP/1.1" 200 -
Message receveid. {'client_msg_id': '369b527f-f72c-4ff1-a8ab-4f5fcdd7b5e0', 'type': 'message', 'text': MESSAGE, 'user': USER, 'ts': '1600246829.001100', 'team': 'T7P9RQX35', 'blocks': [{'type': 'rich_text', 'block_id': 'jg=NL', 'elements': [{'type': 'rich_text_section', 'elements': [{'type': 'text', 'text': MESSAGE}]}]}], 'channel': 'D8X4RT3PW', 'event_ts': '1600246829.001100', 'channel_type': 'im'}
52.23.240.52 - - [16/Sep/2020 11:00:46] "POST /slack/events HTTP/1.1" 200 -
3.88.108.108 - - [16/Sep/2020 11:00:55] "POST /slack/events HTTP/1.1" 200 -
34.235.111.177 - - [16/Sep/2020 11:01:04] "POST /slack/events HTTP/1.1" 200 -
54.145.3.68 - - [16/Sep/2020 11:01:12] "POST /slack/events HTTP/1.1" 200 -
18.233.164.219 - - [16/Sep/2020 11:01:20] "POST /slack/events HTTP/1.1" 200 -
Message receveid. {'client_msg_id': '369b527f-f72c-4ff1-a8ab-4f5fcdd7b5e0', 'type': 'message', 'text': MESSAGE, 'user': USER, 'ts': '1600246829.001100', 'team': 'T7P9RQX35', 'blocks': [{'type': 'rich_text', 'block_id': 'jg=NL', 'elements': [{'type': 'rich_text_section', 'elements': [{'type': 'text', 'text': MESSAGE}]}]}], 'channel': 'D8X4RT3PW', 'event_ts': '1600246829.001100', 'channel_type': 'im'}
52.55.13.9 - - [16/Sep/2020 11:01:44] "POST /slack/events HTTP/1.1" 200 -
18.212.93.51 - - [16/Sep/2020 11:02:01] "POST /slack/events HTTP/1.1" 200 -

Alright, I am sending them a message.

@alexattia
Copy link
Author

Hello,
The support team answered me and say my endpoint is not consistently acknowledging the Slack event callbacks within 3 seconds.
The response sent back by the bot could take more than 3 seconds, do you know how I can acknowledge directly when I receive a message so it's within 3 seconds.
Thank you in advance,

@seratch
Copy link
Member

seratch commented Sep 18, 2020

⚡️ Bolt app is running! (development server)

I see the above in your comment. I guess you're using App#start(). If your app doesn't have time-consuming operations at all, I guess this may be a matter of the webserver stability.

It's totally fine to use App#start() for local development. App#start() internally uses http.server. It basically works. That said, the production-grade stability and scalability are not guaranteed. Flask's development mode is the same.

For running a long-lived process, I recommend using a production-ready WSGI server (e.g., gunicorn). Here is a simple Dockerfile using Flask along with Gunicorn. https://github.com/slackapi/bolt-python/blob/v0.5.3a0/samples/google_cloud_run/flask-gunicorn/Dockerfile

It may be easier if you use managed services such as Heroku, container services (ECS, etc), or whatever you prefer.

@seratch
Copy link
Member

seratch commented Oct 29, 2020

As I've already answered all questions here, let me close this issue now. Please feel free to write in if you have anything further related to this.

@seratch seratch closed this as completed Oct 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants