bolt-python icon indicating copy to clipboard operation
bolt-python copied to clipboard

Issue in modal submission (We had some trouble connecting.Try again ?)

Open devikaTV opened this issue 5 months ago • 1 comments

I am using socket mode python for a modal triggering with slash command

It has three stages

  • modal triggered through slash command with an input field for GitHub issue id
  • once the modal is submitted , some parsing on the data(GitHub issue id and issue body is retrieved) is done and if no errors, new modal which has multiple input fields(body of above issue) is updated
  • once submitted , retrieve values and update the issue body

The error message is displayed when hitting the submit in first modal , sometimes the modal flow closes at that point or continue to next modal with the same error, sometimes the modal doesn't closes even after submit but the changes intended are reflected

Failed to run listener function (error: The request to the Slack API failed. (url: https://www.slack.com/api/views.update)
The server responded with: {'ok': False, 'error': 'not_found'})

Please help me in figuring out what is going wrong Attaching the code

@app.command("/editTicket")
def open_ticket_modal(ack, body, client):
	ack()
	client.views_open(
		
	    trigger_id=body["trigger_id"],
	    view={
	        "type": "modal",
	        "callback_id": "submit_ticket",
	        "title": {"type": "plain_text", "text": "Edit  Ticket"},
	        "submit": {"type": "plain_text", "text": "Submit"},
	        "blocks": [
	            {
					"type": "input",
					"block_id": "gitissue",
					"element": {
						"type": "plain_text_input",
						"multiline": True,
						"action_id": "gitissue-value",
						"placeholder": {
						"type": "plain_text",
						"text": "Enter ticket link",
						}
					},
					"label": {
						"type": "plain_text",
						"text": " Ticket Link(s):",
						"emoji": True
					}
				},
	        ]
	    }
	)

	

@app.view("submit_ticket")
def handle_ticket_submission(ack,body,client):
	print(body)
	slack_user_id = body["user"]["id"] 
	values = body["view"]["state"]["values"]
	values[""][""]["value"] if "" in values else None
	viewID = body["view"]["id"]
	hashvalue = body["view"]["hash"]

	gitissue = values["gitissue"]["gitissue-value"]["value"] if "gitissue" in values else None

	errors = {}
	gh = issue.J_Git(gh_token)
	exist , issueno = gh.check_if_valid_ticket(gitissue) 
	if not exist :
		print("Enter a valid  ticket link")
		errors["gitissue"] = "Enter a valid  ticket link"
	if slack_user_id not in editAccessGroup:
		print("You do not have permission to edit this ticket")
		errors["gitissue"] = "You do not have permission to edit this ticket"
	
	if len(errors) > 0: 
		ack(response_action="errors", errors=errors)    
	else:

		ack(response_action = "update")	
		#fetching the current value of issue
		values = gh.stripBody(gitissue)
		# global variable - editing ticket- to access it in next callback id function
		global ticket
		ticket = gitissue
		
			
		client.views_update(
        view_id = viewID,
        hash = hashvalue,
        view={
			"type": "modal",
			"callback_id": "submit_edit_ticket",
			"submit": {
				"type": "plain_text",
				"text": "Submit",
				"emoji": True
			},
			"close": {
				"type": "plain_text",
				"text": "Cancel",
				"emoji": True
			},
			"title": {
				"type": "plain_text",
				"text": "Risk Intake Edit Form",
				"emoji": True
			},
			"blocks": [
			...
			
		]
	}
}			

@app.view("submit_edit_ticket")
def handle_edit_submission_event(ack,body,client):
	ack()
	print(body)
	print(ticket)
	slack_user_id = body["user"]["id"] 
	values = body["view"]["state"]["values"]
	values[""][""]["value"] if "" in values else None
	#retrive values of the input fields
	if len(errors) > 0:

		ack(response_action="errors", errors=errors)

	else:
		ack(response_action = "clear" )
		gh = issue.J_Git(gh_token)
		url = gh.update_issue_body(ticket,Body)
		message = f"Hey \nYou can check the updated issue below \n {ticket}"

devikaTV avatar Feb 08 '24 07:02 devikaTV