我正在使用Slack斜杠命令向我的AWS Lambda python应用程序发送请求
但是,在发送命令后,Slack将返回消息failed with the error "operation_timeout"
:
尽管我收到了此消息,但我的请求已成功发送,并且工作已完成
我只是想知道如何摆脱slack发送的消息
我知道Slack期望HTTP POST 200 OK作为来自此链接的确认响应here,但我确实在收到有效负载时发送了一个,如下所示:
slack\u caller.py
from models.exceptions import SlackPayloadProcessing
class SlackCaller:
def __init__(self, payload) -> None:
try:
self.calling_channel_id = payload['channel_id'][0]
self.calling_channel_name = payload['channel_name'][0]
self.user = payload['user_name'][0]
self.response_url = payload['response_url'][0]
except:
raise SlackPayloadProcessing("Cannot process payload.")
lambda_handler.py
def slack_acknowledgment_response(resonse_url):
# Make API Call to Slack API
requests.post(
url=resonse_url,
data = {"OK"},
headers={"Content-Type": "application/json"}
)
def validate_request(event):
# Verify if payload sent properly
if "postBody" not in event:
raise SlackPayloadProcessing("Wrong payload provided.")
# Extract data from paylaod
payload = parse_qs(event['postBody'])
# Verify if token provided in payload
if "token" not in payload:
raise SlackPayloadProcessing("Access denied. Token not
provided")
if payload["token"][0] !=
environ["TOKEN_VERIFICATION_SLACK_SYSAPP"]:
raise SlackPayloadProcessing("Access denied. Wrong token
provided")
# return the payload
return payload
# This is my main event
def main(event, context):
slack_caller = None
# Create a unique identifier for the request
unique_request_id = uuid.uuid4().hex[:12].upper()
try:
# Perform several checks to validate
# whether the request has been sent in the correct format
# If exception occurs, it will trigger the
# SlackPayloadProcessing Exception
payload = validate_request(event)
# Construct Slack Channel model
# Will get details like user name
# channel id, response url etc..
slack_caller = SlackCaller(payload)
# Here i send the acknowledgement request
slack_acknowledgment_response(slack_caller.response_url)
有人能帮忙吗
目前没有回答
相关问题 更多 >
编程相关推荐