Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
danbilokha committed Apr 18, 2020
1 parent e50ea71 commit 52ca085
Show file tree
Hide file tree
Showing 40 changed files with 1,134 additions and 993 deletions.
5 changes: 5 additions & 0 deletions .huskyrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"hooks": {
"pre-commit": "lint-staged"
}
}
7 changes: 7 additions & 0 deletions .lintstagedrc.json
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"
]
}
8 changes: 8 additions & 0 deletions .prettierrc.json
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
}
16 changes: 16 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 4 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"build": "webpack --config webpack.config.js",
"start:watch": "ts-node-dev --respawn --transpileOnly server/src/index.ts",
"start:inspect": "ts-node-dev --inspect --respawn --transpileOnly server/src/index.ts",
"lint": "tslint \"server/src/**/*.ts\"",
"lint:fix": "tslint \"server/src/**/*.ts\" --fix"
"tslint": "tslint \"server/src/**/*.ts\"",
"tslint:fix": "tslint \"server/src/**/*.ts\" --fix"
},
"homepage": "https://github.com/danbilokha/covid19liveupdates",
"bugs": {
Expand Down Expand Up @@ -50,13 +50,15 @@
"@types/dotenv": "^8.2.0",
"@types/express": "^4.17.3",
"@types/jest": "^25.1.4",
"@types/node-telegram-bot-api": "^0.40.3",
"@types/supertest": "^2.0.8",
"chai": "^4.2.0",
"coveralls": "^3.0.11",
"husky": "^4.2.5",
"jest": "^25.3.0",
"lint-staged": "^10.1.3",
"mocha": "^7.1.0",
"prettier": "2.0.4",
"supertest": "^4.0.2",
"ts-jest": "^25.3.1",
"ts-loader": "^6.2.1",
Expand Down Expand Up @@ -86,16 +88,6 @@
"url": "https://github.com/danbilokha"
}
],
"lint-staged": {
"server/src/**/*.ts": [
"npm run lint:fix && npm run lint"
]
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"jest": {
"globals": {
"ts-jest": {
Expand Down
9 changes: 5 additions & 4 deletions server/src/bots/telegram/botResponse/adviceResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,23 @@ import {
encouragingMessage,
getCovid19ExplanationVideo,
socialDistancing,
suggestedBehaviors
suggestedBehaviors,
} from '../../../messages/feature/adviceMessages';
import {CallBackQueryHandler} from '../models';
import { CallBackQueryHandler } from '../models';
import * as TelegramBot from 'node-telegram-bot-api';

export const showAdvicesHowToBehaveResponse: CallBackQueryHandler = async (
bot,
message,
chatId
): Promise<void> => {
): Promise<TelegramBot.Message> => {
return bot.sendMessage(
chatId,
`ℹ Suggested Behaviors for ${getCovid19ExplanationVideo()}
${suggestedBehaviors()} \nℹ Social Distancing
${socialDistancing()} \nℹ Alternative Greetings
${alternativeGreetings()} \n${encouragingMessage()}
`,
{parse_mode: 'HTML'}
{ parse_mode: 'HTML' }
);
};
87 changes: 48 additions & 39 deletions server/src/bots/telegram/botResponse/assistantResponse.ts
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));
};
20 changes: 11 additions & 9 deletions server/src/bots/telegram/botResponse/availableResponse.ts
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));
};

0 comments on commit 52ca085

Please sign in to comment.