Slash Command - failed with error dispatch_failed

SAM321
Tera Contributor

Hi all, Iam trying to get the payload of slash command(/procurement) used in slack to servicenow log..But its showing error. as 

/procurement failed with the error "dispatch_failed"'
Below is the scripted rest Api.

(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
 
    if (request.body.data.challenge){
response.setStatus(200);
response.setContentType('text/plain');
response.getStreamWriter().writeString(request.body.data.challenge);
 
}else{
if(request.body.data.event.text.contains('/procurement')){
gs.info('Slack Payload:'+ JSON.stringify(request.body.data));
 
}
}
 
})(request, response);

 

 

 

6 REPLIES 6

Sai Shravan
Mega Sage

Hi @SAM321 ,

 

Below is the modified script

(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
  if (request.body.data.challenge) {
    response.setStatus(200);
    response.setContentType('text/plain');
    response.getStreamWriter().writeString(request.body.data.challenge);
  } else {
    if (request.body.data.event && request.body.data.event.text && request.body.data.event.text.includes('/procurement')) {
      gs.info('Slack Payload: ' + JSON.stringify(request.body.data.event));
    }
  }
})(request, response);

This change ensures that the text field is present in request.body.data.event and then checks if it contains the '/procurement' command.

 

Regards

Shravan

Please mark this as helpful and correct answer, if this helps you

 

SAM321
Tera Contributor

@Sai Shravan   

 Hi still the error in slack ...'/procuremnt  failed with the error "dispatch_failed" ..'

just now checked .. in logs its showing ...'Requested URI does not represent any resource: /934350/procurement_slack: no thrown error'

SAM321
Tera Contributor

@Sai Shravan Hi sir, when i place some text before /procurement. the payload is getting created...How ever i need payload only just by selecting the /procurement command in slack.. as it will have trigger id in that payload

Mahesh23
Mega Sage

Hello,

 

Are you able to solve this issue..?