Skip to content

Commit

Permalink
translate some EU texts into UA; improved UX; connected some features…
Browse files Browse the repository at this point in the history
… together in coherent flow
  • Loading branch information
danbilokha committed May 2, 2020
1 parent e778547 commit be540d2
Show file tree
Hide file tree
Showing 12 changed files with 252 additions and 117 deletions.
27 changes: 24 additions & 3 deletions server/src/bots/telegram/botResponse/countriesResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
getTableHeader,
} from '../../../messages/feature/countriesMessages';
import {
getContinentCountriesCheckOutOfferMessageInlineKeyboard,
getContinentsInlineKeyboard,
getCountriesInlineKeyboard,
} from '../services/keyboard';
Expand All @@ -23,6 +24,8 @@ import {
getWorldOverallInformation,
} from '../../../services/domain/countries';
import * as TelegramBot from 'node-telegram-bot-api';
import { Continents } from '../../../models/constants';
import { isTextEqual } from '../../../utils/isEqual';

export const countriesForContinentResponse = async ({
bot,
Expand All @@ -45,7 +48,7 @@ export const countriesForContinentResponse = async ({
);
};

export const countriesTableByContinentResponse = (continent) => async ({
export const countriesTableByContinentResponse = (continent: string) => async ({
bot,
user,
chatId,
Expand Down Expand Up @@ -84,8 +87,9 @@ export const countriesTableByContinentResponse = (continent) => async ({
{
parse_mode: 'HTML',
reply_markup: {
inline_keyboard: getCountriesInlineKeyboard(
sortedCountriesSituation
inline_keyboard: getContinentCountriesCheckOutOfferMessageInlineKeyboard(
user.settings?.locale,
continent
),
},
}
Expand All @@ -96,7 +100,24 @@ export const worldByContinentOverallResponse: CallBackQueryHandlerWithCommandArg
bot,
user,
chatId,
message,
commandParameter,
}: CallBackQueryParameters) => {
if (
!!commandParameter &&
Object.keys(Continents).some((continent) =>
isTextEqual(continent, commandParameter)
)
) {
return countriesForContinentResponse({
bot,
user,
chatId,
message,
commandParameter,
});
}

const {
confirmed,
recovered,
Expand Down
6 changes: 3 additions & 3 deletions server/src/bots/telegram/botResponse/helpResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
CallBackQueryParameters,
} from '../models';
import * as TelegramBot from 'node-telegram-bot-api';
import { getFullMenuKeyboard } from '../services/keyboard';
import { getFullClickableFeaturesInlineKeyBoard } from '../services/keyboard';

export const helpInfoResponse: CallBackQueryHandlerWithCommandArgument = async ({
bot,
Expand All @@ -13,7 +13,7 @@ export const helpInfoResponse: CallBackQueryHandlerWithCommandArgument = async (
}: CallBackQueryParameters): Promise<TelegramBot.Message> => {
return bot.sendMessage(
chatId,
getHelpMessage(),
getFullMenuKeyboard(chatId, user.settings?.locale)
getHelpMessage(user.settings?.locale),
getFullClickableFeaturesInlineKeyBoard(user.settings?.locale)
);
};
8 changes: 6 additions & 2 deletions server/src/bots/telegram/botResponse/settingsResponse.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { getLocalizationInlineKeyboard } from '../services/keyboard';
import {
getFullMenuKeyboard,
getLocalizationInlineKeyboard,
} from '../services/keyboard';
import {
CallBackQueryHandlerWithCommandArgument,
CallBackQueryParameters,
Expand Down Expand Up @@ -68,6 +71,7 @@ export const settingsLanguageResponse: CallBackQueryHandlerWithCommandArgument =
// We cannot use "User" from parameter in the bot.sendMessage(
// because that "User" still have an old locale, while this
// "resultUser" has updated user settings
languageHasBeenSuccessfullySetup(updatedUser.settings.locale)
languageHasBeenSuccessfullySetup(updatedUser.settings.locale),
getFullMenuKeyboard(chatId, updatedUser.settings?.locale)
);
};
4 changes: 2 additions & 2 deletions server/src/bots/telegram/botResponse/startResponse.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getHelpProposalInlineKeyboard } from '../services/keyboard';
import { getFullMenuKeyboard } from '../services/keyboard';
import { greetUser } from '../../../messages/userMessage';
import {
CallBackQueryHandlerWithCommandArgument,
Expand Down Expand Up @@ -30,6 +30,6 @@ export const startResponse: CallBackQueryHandlerWithCommandArgument = async ({
return bot.sendMessage(
chatId,
greetUser(locale, user),
getHelpProposalInlineKeyboard(locale)
getFullMenuKeyboard(chatId, locale)
);
};
6 changes: 3 additions & 3 deletions server/src/bots/telegram/botResponse/trendResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ export const trendsByCountryResponse: CallBackQueryHandlerWithCommandArgument =

let model = enrichWithTitle(
Transform(periodSituation),
getLocalizedMessages(user.settings.locale, frequencyName) +
getLocalizedMessages(user.settings.locale, 'trends for') +
getLocalizedMessages(user.settings?.locale, frequencyName) +
getLocalizedMessages(user.settings?.locale, 'trends for') +
capitalize(
getLocalizedMessages(user.settings.locale, requestedCountry)
getLocalizedMessages(user.settings?.locale, requestedCountry)
)
);
if (frequency === Frequency.Weekly) {
Expand Down
5 changes: 4 additions & 1 deletion server/src/bots/telegram/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,10 @@ export async function runTelegramBot(
)
// Settings
.registerMessageHandler(
[UserSettingsRegExps.Language],
[
...localizeOnLocales(availableLanguages, UserMessages.Language),
UserSettingsRegExps.Language,
],
withSingleParameterAfterCommand(
messageHandlerRegistry,
settingsLanguageResponse
Expand Down
78 changes: 76 additions & 2 deletions server/src/bots/telegram/services/keyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ export const getFullMenuKeyboard = (

rk.addRow(
getLocalizedMessages(locale, UserMessages.CountriesData),
getLocalizedMessages(locale, UserMessages.AvailableCountries)
getLocalizedMessages(locale, UserMessages.SubscriptionManager)
)
.addRow(
getLocalizedMessages(locale, UserMessages.Assistant),
getLocalizedMessages(locale, UserMessages.GetAdviceHowToBehave)
)
.addRow(
getLocalizedMessages(locale, UserMessages.SubscriptionManager),
getLocalizedMessages(locale, UserMessages.Language),
getLocalizedMessages(locale, UserMessages.Help)
);

Expand Down Expand Up @@ -182,6 +182,28 @@ export const getLocalizationInlineKeyboard = (
return ik.build();
};

export const getContinentCountriesCheckOutOfferMessageInlineKeyboard = (
locale: string,
continent: string
): Array<Array<TelegramBot.InlineKeyboardButton>> => {
const inlineKeyboard = [];

inlineKeyboard.push([
{
text: getLocalizedMessages(locale, 'Get all continents'),
callback_data: UserRegExps.CountriesData,
},
{
text: getLocalizedMessages(locale, [
[`Check %s countries out`, continent],
]).join(''),
callback_data: `${UserRegExps.CountriesData} ${continent}`,
},
]);

return inlineKeyboard;
};

export const getCountriesInlineKeyboard = (
countries: Array<Country>
): TelegramBot.SendMessageOptions => {
Expand All @@ -206,6 +228,58 @@ export const getCountriesInlineKeyboard = (
return ik.build();
};

export const getFullClickableFeaturesInlineKeyBoard = (
locale: string
): TelegramBot.SendMessageOptions => {
const ik = new InlineKeyboard();

ik.addRow(
{
text: getLocalizedMessages(locale, UserMessages.CountriesData),
callback_data: UserRegExps.CountryData,
},
{
text: getLocalizedMessages(locale, UserMessages.AvailableCountries),
callback_data: UserRegExps.AvailableCountries,
}
)
.addRow(
{
text: getLocalizedMessages(locale, UserMessages.Assistant),
callback_data: UserRegExps.Assistant,
},
{
text: getLocalizedMessages(
locale,
UserMessages.GetAdviceHowToBehave
),
callback_data: UserRegExps.Advice,
}
)
.addRow(
{
text: getLocalizedMessages(locale, UserMessages.Existing),
callback_data: UserRegExps.Subscribe,
},
{
text: getLocalizedMessages(locale, UserMessages.Unsubscribe),
callback_data: UserRegExps.Unsubscribe,
}
)
.addRow(
{
text: getLocalizedMessages(locale, 'Choose language'),
callback_data: UserSettingsRegExps.Language,
},
{
text: getLocalizedMessages(locale, UserMessages.Help),
callback_data: UserRegExps.Help,
}
);

return ik.build();
};

const getCloseInlineKeyboardRow = (
locale: string
): TelegramBot.InlineKeyboardButton => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const withTwoArgumentsAfterCommand = (
return handlerFn.call(context, {
bot,
message,
user,
chatId,
commandParameter:
(arg1 && arg1.toLowerCase()) || commandParameter,
Expand Down

0 comments on commit be540d2

Please sign in to comment.