1

We need to call JIRA Rest API to get a specific information from the given query in Dialogflow.

We need to provide response to user based on the response from the API. However, the Dialogflow is unable to retrieve any response from JIRA API through the fulfillment in Firebase Cloud function as it's always timeout.

Based on the log in Firebase console, it always take more than 6000 ms for the execution.

Meanwhile if I use postman to call the JIRA REST API, it takes less than 1 second to get the response.

Some said we need to use promise but I does not seem to work as well. Please help how should I solve this problem?

Please see my code below

function checkcontract(agent){
       var parameters = request.body.queryResult.parameters;
       var customer_id = parameters.customer_id;
       var bodyData = JSON.stringify({"jql": "project = CDB AND 'Customer ID' ~ "+customer_id,
                  "maxResults": 1,
                  "fieldsByKeys": false,
                  "fields":  [
                    "summary",
                    "customfield_11949", //Customer ID custom field
                    "customfield_11937", // Contract Start Date
                    "customfield_11938", //Contract End Date
                    "customfield_11936", //email
                    "customfield_11946", //default JSD request id
                    "customfield_11943", //project id
                    "customfield_11941" //project key
                  ],
                "startAt": 0
                });

      var options = {
         method: 'POST',
         url: '/rest/api/3/search',
         auth: { bearer: authorization_token },
         headers: {
            'Accept': 'application/json',
            'Content-Type': 'application/json'
         },
         body: bodyData
      };
        request(options, function (error, response, body) {
           if (error) throw new Error(error);
           console.log(
              'Response: ' + response.statusCode + ' ' + response.statusMessage
           );
           console.log(body);
        });
     }

EDIT: JIRA API returns a response to the function. But the agent.add("message") does not return anything to the chat.

Priska Aprilia
  • 1,149
  • 1
  • 15
  • 34

0 Answers0