I'm building a bot through botkit and it is using Zendesk api to pull information.
I have a function that asks a user for a search term and the bot searches relevant information about that search term. It pulls the information from the Zendesk API and outputs the answer.
My problem is when the user types the search term 'Jim', it will work correctly and pull back information from the tickets[0] element.
However, when a user types in another word like 'Steve', it will not work. I understand that at the moment the function has nothing set to return when it cannot find anything.
Here is my original code:
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[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();
});
});
});
});
I'm thinking of attempting the problem like this:
try{
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[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();
});
});
});
}catch (err)
console.log('Nothing Found');
bot.reply(message, 'I could not find anything.');
});
However, it doesn't output that response.
Here is a link to the botkit documentation: https://github.com/howdyai/botkit
Here is a link to the zendesk API documentation: https://developer.zendesk.com/rest_api/docs/core/tickets#list-tickets
via traveler316
No comments:
Post a Comment