Title: I would like to refer to X-Slack-Retry-Num. · Issue #731 · slackapi/bolt-python · GitHub
Open Graph Title: I would like to refer to X-Slack-Retry-Num. · Issue #731 · slackapi/bolt-python
X Title: I would like to refer to X-Slack-Retry-Num. · Issue #731 · slackapi/bolt-python
Description: I want to deploy a Slack bolt using Cloud Function, but since I can't use lazy listener, I use Thread for parallel processing. When I deploy to Cloud Function with the following code, I get duplicate messages the first time. After that, ...
Open Graph Description: I want to deploy a Slack bolt using Cloud Function, but since I can't use lazy listener, I use Thread for parallel processing. When I deploy to Cloud Function with the following code, I get duplica...
X Description: I want to deploy a Slack bolt using Cloud Function, but since I can't use lazy listener, I use Thread for parallel processing. When I deploy to Cloud Function with the following code, I get dup...
Opengraph URL: https://github.com/slackapi/bolt-python/issues/731
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"I would like to refer to X-Slack-Retry-Num.","articleBody":"I want to deploy a Slack bolt using Cloud Function, but since I can't use lazy listener, I use **Thread** for parallel processing. When I deploy to Cloud Function with the following code, I get duplicate messages the first time. After that, it only needs to be done once. However, after some time passes, duplicate messages are sent again.\r\n Therefore, **I would like to implement a process that only returns a response if there is an X-Slack-Retry-Num in the header**, but I do not know how to get the header. \r\nI implemented the following code in Python this way,\r\n\r\n```Python\r\n if \"X-Slack-Retry-Num\" in event[\"headers\"]:\r\n return {'statusCode': 200, 'body': 'this request is retry'}\r\n\r\n```\r\n\r\n Ended with an error result.\r\n```\r\n if \"X-Slack-Retry-Num\" in event[\"headers\"]:\r\nKeyError: 'headers'\r\n```\r\nPlease let me know if there is a better solution.\r\n\r\n### This is my code:\r\n\r\n```Python\r\nimport os\r\nimport logging\r\nfrom slack_bolt import App\r\nfrom slack_bolt import Say\r\nfrom slack_bolt.adapter.socket_mode import SocketModeHandler\r\nfrom slack_sdk import WebClient\r\nimport functions_framework\r\nimport deepl\r\nimport langid\r\nimport json\r\nfrom slack_bolt.adapter.flask import SlackRequestHandler\r\n\r\n\r\nlogging.basicConfig(level=logging.DEBUG)\r\n\r\nDEEPL_API_TOKEN = os.environ[\"DEEPL_API_TOKEN\"]\r\nSLACK_BOT_TOKEN = os.environ[\"SLACK_BOT_TOKEN\"]\r\n\r\napp = App(\r\n token=SLACK_BOT_TOKEN,\r\n signing_secret=os.environ.get(\"SLACK_SIGNING_SECRET\"),\r\n process_before_response=True\r\n )\r\nhandler = SlackRequestHandler(app)\r\n\r\nclient = WebClient(SLACK_BOT_TOKEN)\r\ntranslator = deepl.Translator(DEEPL_API_TOKEN)\r\n\r\n\r\n@app.middleware\r\ndef log_request(logger, body, next):\r\n logger.debug(body)\r\n return next()\r\n\r\n\r\n\r\n@app.event(\"reaction_added\")\r\ndef show_datepicker(event,say: Say):\r\n reaction = event[\"reaction\"]\r\n replies = say.client.conversations_replies(channel=event[\"item\"][\"channel\"], ts=event[\"item\"][\"ts\"])\r\n print(\"replies is:\",replies)\r\n message = replies[\"messages\"][0][\"text\"]\r\n print(\"message is:\",message)\r\n lang = langid.classify(replies[\"messages\"][0][\"text\"])\r\n print(\"languages[0] is:\",lang[0])\r\n\r\n\r\n if reaction == \"eyes\":\r\n if lang[0] == \"ja\":\r\n target_lang = \"EN-US\"\r\n elif lang[0] == \"en\":\r\n target_lang = \"JA\"\r\n else:\r\n return\r\n result = translator.translate_text(message, target_lang=target_lang)\r\n query = \"\"\r\n for m in message.split(\"\\n\"):\r\n query += f\">{m}\\n\"\r\n say(\r\n thread_ts=replies[\"messages\"][0].get(\"ts\"),\r\n text=f\"{query}{result.text}\"\r\n ) \r\n return \r\n\r\n\r\nfrom threading import Thread\r\n\r\n@functions_framework.http\r\ndef slack_bot(request):\r\n request_data = request.form\r\n t = Thread(target=show_datepicker, kwargs={'request_data': request_data})\r\n t.start()\r\n return handler.handle(request)\r\n \r\nif __name__ == \"__main__\":\r\n app.start(port=int(os.environ.get(\"PORT\", 3000)))\r\n```\r\n\r\n#### The `slack_bolt` version\r\n\r\nslack-bolt==1.14.3\r\nslack-sdk==3.18.3\r\n#### Python runtime version\r\n\r\nPython 3.9.12\r\n\r\n### Expected result:\r\n\r\nI want to prevent duplicate messages.\r\n### Actual result:\r\n\r\nDuplicate messages more than three times\r\n","author":{"url":"https://github.com/iwakiri0104","@type":"Person","name":"iwakiri0104"},"datePublished":"2022-10-04T04:33:51Z","url":"https://github.com/slackapi/bolt-python/issues/731"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:b44bfd19-cce2-fcda-82d6-5cd17f845e1d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 986C:5EE3D:31E705:40580D:6AFF879B |
| html-safe-nonce | db25d38c8909e57777b94f60e5c2fcee1063600bce816eef9655a9ea77914fd4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5ODZDOjVFRTNEOjMxRTcwNTo0MDU4MEQ6NkFGRjg3OUIiLCJ2aXNpdG9yX2lkIjoiNDE4ODUxNTAzODcxNTE1MjI4MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 2c5cd62aec9f18cf2cc2245459581a370e18910784bf7e87b2fadc2d4366c3ee |
| hovercard-subject-tag | issue:1395651911 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/slackapi/bolt-python/731/issue_layout |
| twitter:image | https://opengraph.githubassets.com/97ab3457c9a50bf9e75ff7f48b82fddf306430cb27d98c0bf67675eca55da182/slackapi/bolt-python/issues/731 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/97ab3457c9a50bf9e75ff7f48b82fddf306430cb27d98c0bf67675eca55da182/slackapi/bolt-python/issues/731 |
| og:image:alt | I want to deploy a Slack bolt using Cloud Function, but since I can't use lazy listener, I use Thread for parallel processing. When I deploy to Cloud Function with the following code, I get duplica... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | iwakiri0104 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 587ad99a3e443b2e1cb0d3df059ec49ab54389861f13310766dfdeb615fed90d |
| turbo-cache-control | no-preview |
| go-import | github.com/slackapi/bolt-python git https://github.com/slackapi/bolt-python.git |
| octolytics-dimension-user_id | 6962987 |
| octolytics-dimension-user_login | slackapi |
| octolytics-dimension-repository_id | 268795735 |
| octolytics-dimension-repository_nwo | slackapi/bolt-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 268795735 |
| octolytics-dimension-repository_network_root_nwo | slackapi/bolt-python |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 5bb0fb68d64881d1344f5863d809515d496801e5 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width