// handler for search queries
//
// query is the received search term from user, bot is BotAPI, update is arrived telegram update
handler for search queries

query is the received search term from user, bot is BotAPI, update is arrived telegram update
// handler for search queries // // query is the received search term from user bot is BotAPI update is arrived telegram update
func handleSearch(query string, bot *tgbotapi.BotAPI, update tgbotapi.Update) {
	resChan := make(chan []searchApi.AppleSearchAppInfo)
	go searchApi.SearchApp(resChan, query)
	results := <-resChan
	if len(results) < 1 {
		msg := tgbotapi.NewMessage(update.Message.Chat.ID, "No result found.")
		bot.Send(msg)
		return
	}
	var rows = make([][]tgbotapi.KeyboardButton, len(results))
	for i := 0; i < len(results); i++ {
		rows[i] = tgbotapi.NewKeyboardButtonRow(
			tgbotapi.NewKeyboardButton("(ID: " + strconv.FormatInt(results[i].IosId, 10) + ") - " + results[i].Name),
		)
	}
	msg := tgbotapi.NewMessage(update.Message.Chat.ID, "Choose one of Results:")
	replayKeyboardMarkup := tgbotapi.NewReplyKeyboard(rows...)
	replayKeyboardMarkup.OneTimeKeyboard = true
	msg.ReplyMarkup = replayKeyboardMarkup
	bot.Send(msg)
	saveResultsToCache(results)
}
func handleSearch ( query string , bot * tgbotapi . BotAPI , update tgbotapi . Update ) { resChan := make ( chan [ ] searchApi . AppleSearchAppInfo ) go searchApi . SearchApp ( resChan , query ) results := <- resChan if len ( results ) < 1 { msg := tgbotapi . NewMessage ( update . Message . Chat . ID , " " ) bot . Send ( msg ) return } var rows = make ( [ ] [ ] tgbotapi . KeyboardButton , len ( results ) ) for i := 0 ; i < len ( results ) ; i ++ { rows [ i ] = tgbotapi . NewKeyboardButtonRow ( tgbotapi . NewKeyboardButton ( " " + strconv . FormatInt ( results [ i ] . IosId , 10 ) + " " + results [ i ] . Name ) , ) } msg := tgbotapi . NewMessage ( update . Message . Chat . ID , " " ) replayKeyboardMarkup := tgbotapi . NewReplyKeyboard ( rows ... ) replayKeyboardMarkup . OneTimeKeyboard = true msg . ReplyMarkup = replayKeyboardMarkup bot . Send ( msg ) saveResultsToCache ( results ) }
handler for search queries
handler for search queries