나는 botkit으로 빌드 된 Zendesk API를 사용하여 정보를 가져 오는 봇을 보유하고 있습니다.API 및 JSON을 올바르게 사용하는 방법은 무엇입니까?
나는 사용자에게 검색어를 물어보고 해당 검색어에 대한 관련 정보를 검색하는 기능이 있습니다. Zendesk API에서 정보를 가져 와서 대답을 출력합니다.
개체 값에 액세스 할 때 일부 값은 출력 될 수없는 반면 일부 값은 출력되지 않을 수 있습니다.
예를 들어, 사용자가 검색어로 'jim'을 제출하면. 티켓 [0] .id + 티켓 [0]. 우선권 + 티켓 [0] .subject + tickets [0] .description.
내가 다음과 같이하면 : tickets [4] - 정의되지 않은 값을 얻습니다.
내가 할 노력하고있어의 전체 코드는 다음과 같습니다
controller.hears(['SEARCH TICKET',/search ticket/gi, /^.{0,}jirabot.
{0,}$/],
['direct_message','direct_mention','mention','ambient'],function(bot,message)
{
// start a conversation to handle this response.
bot.startConversation(message,function(err,convo) {
convo.ask('What are you looking for?',function(response,convo) {
zendesk.search.list('query='+response.text+'&sort_by=priority&sort_order=desc').then(function(tickets){
console.log(tickets);
bot.reply(message, 'The Ticket ID Number: ' + tickets[3] + tickets[0].id + '\n The Ticket Priority: ' + tickets[0].priority + '\n The Ticket Subject: ' + tickets[0].subject + '\n The Ticket Description: \n'+ tickets[0].description + '\n');
convo.next();
}
});
});
});
});
다음
json으로이 모습입니다 :
{
"results": [(in here is the information like ticket subject, priority, id,
etc.],
"facets": null,
"next_page": null,
"previous_page": null,
"count": 2
}
가 어떻게 계수의 값을받을 수 있나요? 내가 표를 할 때 나는 정의되지 않는다.
을 써야합니다. JSON이 어떻게 생겼는지 보여줍니다. - 티켓 [0] .id + 티켓 [0] .priority + tickets [0] .subject + 티켓 [0] .description' –
결과 배열 내에서 티켓 [0] .id를 사용하여 값을 얻을 수 있습니다. 따라서 티켓 배열의 첫 번째 요소에서 값을 얻을 수는 있지만 티켓을 만들 때 어떤 이유로 인해 정의되지 않습니다. –
아마도 4 개의 결과가 있습니까? 즉 0, 1, 2 및 3 - 응답의 가장 중요한 부분은 아이러니하게도 표시하지 않은 부분입니다. –