Skip to content

Commit

Permalink
fix build; add main menu appearance for viber notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
danbilokha committed May 7, 2020
1 parent da2ffae commit bf4bc78
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export class TelegramMessageRegistry extends MessageRegistry {
}

public sendUserNotification(
locale: string,
chatId: number,
notification: string
): Promise<TelegramBot.Message> {
Expand Down
12 changes: 0 additions & 12 deletions server/src/bots/viber/services/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,6 @@ import { viberStorage } from './storage';
import { StorageService } from '../../../services/domain/storage.service';
import { User } from '../../../models/user.model';

class ViberUserService extends UserService {
constructor(protected storage: StorageService) {
super(storage);
}

public getUser(user: number | string): Promise<User | null>;
public getUser(user: User): Promise<User | null>;
public getUser(user: User | number | string): Promise<User | null> {
return super.getUser(user);
}
}

export function viberUserService() {
let userService;
return (() => {
Expand Down
17 changes: 11 additions & 6 deletions server/src/bots/viber/services/viberMessageRegistry.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { MessageRegistry } from '../../../services/domain/registry/messageRegistry';
import { ViberBot, ViberTextMessage } from '../models';
import { getViberChatId } from '../utils/getViberChatId';
import {
getViberChatId,
mapBackToRealViberChatId,
} from '../utils/getViberChatId';
import { DEFAULT_USER_SETTINGS, User } from '../../../models/user.model';
import * as TelegramBot from 'node-telegram-bot-api';
import { UserService } from '../../../services/domain/user.service';
import { logger } from '../../../utils/logger';
import { LogCategory } from '../../../models/constants';
import { Message } from 'viber-bot';
import { vGetFullMenuKeyboard } from './keyboard';

export class ViberMessageRegistry extends MessageRegistry {
public getChatId: (params: ViberTextMessage) => string = getViberChatId;
Expand Down Expand Up @@ -34,13 +38,14 @@ export class ViberMessageRegistry extends MessageRegistry {
}

public sendUserNotification(
chatId: number,
locale: string,
chatId: string,
notification: string
): Promise<TelegramBot.Message> {
return this.bot.sendMessage(
{ id: mapBackToRealViberChatId(chatId).toString() },
new Message.Text(notification)
);
return this.bot.sendMessage({ id: mapBackToRealViberChatId(chatId) }, [
new Message.Text(notification),
new Message.Keyboard(vGetFullMenuKeyboard(locale, chatId)),
]);
}

protected createUser(message: ViberTextMessage, chatId: number): User {
Expand Down
1 change: 1 addition & 0 deletions server/src/services/domain/registry/messageRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ export abstract class MessageRegistry {
}

public abstract sendUserNotification(
locale: string,
chatId: number | string,
notification: string
): Promise<Message>;
Expand Down
1 change: 1 addition & 0 deletions server/src/services/domain/subscription.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ const getAndSendUserNotificationSubscriptions = async (
sendingNotificationResult,
] = await catchAsyncError(
messageHandlerRegistry.sendUserNotification(
settings?.locale,
chatId,
userSubscriptionsUpdate
.map(
Expand Down
6 changes: 5 additions & 1 deletion server/src/services/infrastructure/scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ export const runSendScheduledNotificationToUsersJob = async (

for (const user of users) {
message.replace('#UserName#', getUserName(user));
messageRegistry.sendUserNotification(user.chatId, message);
messageRegistry.sendUserNotification(
user.settings?.locale,
user.chatId,
message
);
}
}
);
Expand Down

0 comments on commit bf4bc78

Please sign in to comment.