Currently have an Azure function(python) which responds to the challenge from the slack and triggers another function to send the message to my slack channel. I want to listen to events(simple hello from any user) and send the message to the channel with bot ideally in threads but can be in the channel as well. But with bolt framework it doesn't work ((
what i tried
import azure.functions as func
from slack_bolt import App
import json
import os
# Initializes your app with your bot token and signing secret
app = App(
token=os.environ.get("SLACK_BOT_TOKEN"),
signing_secret=os.environ.get("SLACK_SIGNING_SECRET")
)
# Listens to incoming messages that contain "hello"
@app.message("hello")
def message_hello(message,say):
# say() sends a message to the channel where the event was triggered
say(f"Hey there <@{message['user']}>")
def main(req: func.HttpRequest) -> func.HttpResponse:
try:
# checking if in req http request has a json and putting this value into req_body
req_body = req.get_json()
except ValueError:
return func.HttpResponse("Invalid JSON in request body", status_code=400)
request_type = req_body.get('type')# here we are getting the request type value
if request_type == 'url_verification': #checking if the request type is url_verification
challenge = req_body.get('challenge') #from request type we are getting challenge value
if challenge: # if challenge is has something in it
#Responding with the challenge in JSON format
response_data ={"challenge":challenge} #creating a dict for storing challenge key is challenge
#returning the response with json format
return func.HttpResponse(json.dumps(response_data),status_code=200, mimetype="application/json")
else:
# Missing challenge parameter in the request
return func.HttpResponse("Missing challenge parameter in the request", status_code=400)
else:
# Respond to other types of requests as needed
return func.HttpResponse("Unhandled request type", status_code=400)
#start our app
if __name__=="__main__":
app.start(port=int(os.environ.get("PORT", 3000)))