-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e50ea71
commit 52ca085
Showing
40 changed files
with
1,134 additions
and
993 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"hooks": { | ||
"pre-commit": "lint-staged" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"server/src/**/*.ts": [ | ||
"prettier --write", | ||
"npm run tslint:fix", | ||
"npm run tslint" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"printWidth": 100, | ||
"tabWidth": 4, | ||
"trailingComma": "es5", | ||
"singleQuote": true, | ||
"jsxBracketSameLine": false, | ||
"bracketSpacing": true | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 48 additions & 39 deletions
87
server/src/bots/telegram/botResponse/assistantResponse.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,75 @@ | ||
import {fetchAnswer, fetchKnowledgeMetainformation} from '../../../services/api/api-knowledgebase'; | ||
import {Answer} from '../../../models/knowledgebase/answer.models'; | ||
import { | ||
fetchAnswer, | ||
fetchKnowledgeMetainformation, | ||
} from '../../../services/api/api-knowledgebase'; | ||
import { Answer } from '../../../models/knowledgebase/answer.models'; | ||
import { | ||
getAnswersOnQuestionMessage, | ||
getAssistantFeaturesMessage, | ||
noAnswersOnQuestionMessage | ||
noAnswersOnQuestionMessage, | ||
} from '../../../messages/feature/assistantMessages'; | ||
import {textAfterUserCommand} from '../../../utils/textAfterCommand'; | ||
import {isCommandOnly, isMatchingDashboardItem, isMessageStartsWithCommand} from '../../../utils/incomingMessages'; | ||
import {KnowledgebaseMeta} from '../../../models/knowledgebase/meta.models'; | ||
import {UserMessages} from '../../../models/constants'; | ||
import {CallBackQueryHandler} from '../models'; | ||
import { textAfterUserCommand } from '../../../utils/textAfterCommand'; | ||
import { | ||
isCommandOnly, | ||
isMatchingDashboardItem, | ||
isMessageStartsWithCommand, | ||
} from '../../../utils/incomingMessages'; | ||
import { KnowledgebaseMeta } from '../../../models/knowledgebase/meta.models'; | ||
import { UserMessages } from '../../../models/constants'; | ||
import { CallBackQueryHandler } from '../models'; | ||
import * as TelegramBot from 'node-telegram-bot-api'; | ||
|
||
export const assistantStrategyResponse: CallBackQueryHandler = async ( | ||
bot, | ||
message, | ||
chatId): Promise<void> => { | ||
if ((isMessageStartsWithCommand(message.text) && isCommandOnly(message.text)) | ||
|| isMatchingDashboardItem(message.text, UserMessages.Assistant)) { | ||
return showAssistantFeatures(bot, message, chatId) as Promise<void>; | ||
bot: TelegramBot, | ||
message: TelegramBot.Message, | ||
chatId?: number | ||
): Promise<TelegramBot.Message> => { | ||
if ( | ||
(isMessageStartsWithCommand(message.text) && isCommandOnly(message.text)) || | ||
isMatchingDashboardItem(message.text, UserMessages.Assistant) | ||
) { | ||
return showAssistantFeatures(bot, message, chatId) as Promise<TelegramBot.Message>; | ||
} | ||
|
||
return answerOnQuestion(bot, message, chatId) as Promise<void>; | ||
return answerOnQuestion(bot, message, chatId) as Promise<TelegramBot.Message>; | ||
}; | ||
|
||
export const showAssistantFeatures: CallBackQueryHandler = async ( | ||
bot, | ||
message, | ||
chatId): Promise<void> => { | ||
bot: TelegramBot, | ||
message: TelegramBot.Message, | ||
chatId: number | ||
): Promise<TelegramBot.Message> => { | ||
const knowledgebaseMeta: KnowledgebaseMeta = await fetchKnowledgeMetainformation(); | ||
return bot.sendMessage( | ||
chatId, | ||
getAssistantFeaturesMessage(knowledgebaseMeta) | ||
) | ||
return bot.sendMessage(chatId, getAssistantFeaturesMessage(knowledgebaseMeta)); | ||
}; | ||
|
||
export const answerOnQuestion: CallBackQueryHandler = async ( | ||
bot, | ||
message, | ||
chatId): Promise<void> => { | ||
const question = textAfterUserCommand(message.text); | ||
bot: TelegramBot, | ||
message: TelegramBot.Message, | ||
chatId: number | ||
): Promise<TelegramBot.Message> => { | ||
const question: string = textAfterUserCommand(message.text); | ||
const answers: Array<Answer> = await fetchAnswer(question); | ||
|
||
if (!answers.length) { | ||
return assistantNoAnswerResponse(bot, message, chatId) as Promise<void>; | ||
return assistantNoAnswerResponse(bot, message, chatId) as Promise<TelegramBot.Message>; | ||
} | ||
|
||
return assistantResponse(bot, answers, chatId); | ||
}; | ||
|
||
export const assistantNoAnswerResponse: CallBackQueryHandler = async ( | ||
bot, | ||
message, | ||
chatId): Promise<void> => { | ||
return bot.sendMessage( | ||
chatId, | ||
noAnswersOnQuestionMessage() | ||
) | ||
bot: TelegramBot, | ||
message: TelegramBot.Message, | ||
chatId: number | ||
): Promise<TelegramBot.Message> => { | ||
return bot.sendMessage(chatId, noAnswersOnQuestionMessage()); | ||
}; | ||
|
||
export const assistantResponse = async (bot, answers, chatId) => { | ||
return bot.sendMessage( | ||
chatId, | ||
getAnswersOnQuestionMessage(answers) | ||
); | ||
export const assistantResponse = async ( | ||
bot: TelegramBot, | ||
answers: Array<Answer>, | ||
chatId: number | ||
) => { | ||
return bot.sendMessage(chatId, getAnswersOnQuestionMessage(answers)); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
import {getAvailableCountries} from '../../../services/domain/covid19'; | ||
import {Country} from '../../../models/country.models'; | ||
import {getShowCountriesMessage} from '../../../messages/feature/availableMessages'; | ||
import {CallBackQueryHandler} from '../models'; | ||
import { getAvailableCountries } from '../../../services/domain/covid19'; | ||
import { Country } from '../../../models/country.models'; | ||
import { getShowCountriesMessage } from '../../../messages/feature/availableMessages'; | ||
import { CallBackQueryHandler } from '../models'; | ||
import * as TelegramBot from 'node-telegram-bot-api'; | ||
|
||
export const showAvailableCountriesResponse: CallBackQueryHandler = async (bot, message, chatId) => { | ||
export const showAvailableCountriesResponse: CallBackQueryHandler = async ( | ||
bot: TelegramBot, | ||
message: TelegramBot.Message, | ||
chatId: number | ||
): Promise<TelegramBot.Message> => { | ||
const countries: Array<Country> = await getAvailableCountries(); | ||
return bot.sendMessage( | ||
chatId, | ||
getShowCountriesMessage(countries), | ||
); | ||
return bot.sendMessage(chatId, getShowCountriesMessage(countries)); | ||
}; |
Oops, something went wrong.