OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

How to read headers that are sent in the webhook URL request

  • Thread starter Thread starter vinod827
  • Start date Start date
V

vinod827

Guest
I'm trying to read the additional custom headers that were sent when I made the curl request using the webhook URL of a Slack channel but I cannot find a way to read the custom header or query parameters. May I know if there is any way to determine them?

Code:
from typing import Optional
import slack_sdk
import os
import logging
from pathlib import Path
from dotenv import load_dotenv
from slack_bolt import App
from slack_bolt.adapter.socket_mode import SocketModeHandler

logging.basicConfig(level=logging.DEBUG)
env_path = Path('.') / '.env'
load_dotenv(dotenv_path=env_path)

SLACK_VERIFICATION_TOKEN = os.environ['SLACK_VERIFICATION_TOKEN']
SLACK_SIGNING_SECRET = os.environ['SLACK_SIGNING_SECRET']
SLACK_BOT_TOKEN = os.environ['SLACK_BOT_TOKEN']
SLACK_APP_TOKEN = os.environ['SLACK_APP_TOKEN']

# Install the Slack app and get xoxb- token in advance
app = App(token=SLACK_BOT_TOKEN, signing_secret=SLACK_SIGNING_SECRET)
    
@app.event("message")
def handle_message(event, say, context):
    text = event["text"]
    channel = event["channel"]
    target_channel='#slave2_public'

    # Access query parameters
    # query_params = context.request.query
    # print("Query Parameters:", query_params)

    # Access headers from the event
    headers = event.get("headers")
    print("Headers:", headers)

    # Access headers
    # headers = context.request.headers
    # print("Headers:", headers)
        

if __name__ == "__main__":
    # export SLACK_APP_TOKEN=xapp-***
    # export SLACK_BOT_TOKEN=xoxb-***
    handler = SocketModeHandler(app, SLACK_APP_TOKEN)
    handler.start()

My curl request to webhook URL:-

Code:
curl -X POST -H 'Content-type: application/json' --data '{"text":"Hello, World!"}' -H "Channel_Name:slave1_private" <webhook URL>
<p>I'm trying to read the additional custom headers that were sent when I made the curl request using the webhook URL of a Slack channel but I cannot find a way to read the custom header or query parameters. May I know if there is any way to determine them?</p>
<pre><code>from typing import Optional
import slack_sdk
import os
import logging
from pathlib import Path
from dotenv import load_dotenv
from slack_bolt import App
from slack_bolt.adapter.socket_mode import SocketModeHandler

logging.basicConfig(level=logging.DEBUG)
env_path = Path('.') / '.env'
load_dotenv(dotenv_path=env_path)

SLACK_VERIFICATION_TOKEN = os.environ['SLACK_VERIFICATION_TOKEN']
SLACK_SIGNING_SECRET = os.environ['SLACK_SIGNING_SECRET']
SLACK_BOT_TOKEN = os.environ['SLACK_BOT_TOKEN']
SLACK_APP_TOKEN = os.environ['SLACK_APP_TOKEN']

# Install the Slack app and get xoxb- token in advance
app = App(token=SLACK_BOT_TOKEN, signing_secret=SLACK_SIGNING_SECRET)

@app.event("message")
def handle_message(event, say, context):
text = event["text"]
channel = event["channel"]
target_channel='#slave2_public'

# Access query parameters
# query_params = context.request.query
# print("Query Parameters:", query_params)

# Access headers from the event
headers = event.get("headers")
print("Headers:", headers)

# Access headers
# headers = context.request.headers
# print("Headers:", headers)


if __name__ == "__main__":
# export SLACK_APP_TOKEN=xapp-***
# export SLACK_BOT_TOKEN=xoxb-***
handler = SocketModeHandler(app, SLACK_APP_TOKEN)
handler.start()
</code></pre>
<p>My curl request to webhook URL:-</p>
<pre><code>curl -X POST -H 'Content-type: application/json' --data '{"text":"Hello, World!"}' -H "Channel_Name:slave1_private" <webhook URL>
</code></pre>
 

Latest posts

M
Replies
0
Views
1
Mohit Pant
M
Top