-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/life notification #60
Conversation
TODO: Handle mapping of user subscription input from inline keyboard to our subscription strategy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool stuff is coming!
Register(message: string, callback: (bot: any, message: any, chatId: unknown) => any) : MessageRegistry { | ||
this._bot.onText(new RegExp(message, 'g'), (message) => callback(this._bot, message, getChatId(message))); | ||
public registerMessageHandler(regexp: string, callback: (bot: unknown, message: unknown, chatId: number) => unknown): MessageRegistry { | ||
this._messageHandlers[regexp] = callback; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I know. When we use this method for subscribing on "onText". we say that on specific type of message which is set by regex under the line we are going to use concrete callback.
A bit different pattern works for when we subscribe for "callback_query". Here we do it only once. And have to handle choosing the callback by ourselves, since there is no parameter like regex for this kind of subscription.
So everything written above is for making sure we both are understanding node telegram API the same way and correctly.
And my actual proposition is just to remove the line 15. 🇺🇬
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see now. You just moved merged it to be a single method.
But my personal opinion is that If api devs made those methods different. It make sense handling them differently and don't mess everything up.
I mean having those handlers registered explicitly in a different way, we will have much clear vision on what user request we actually handle just from code.
It prolly just my thoughts....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reverted back 🥇
@@ -0,0 +1,31 @@ | |||
import * as firebase from 'firebase'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love seeing third party services reused within our App.
Firebase ❤️
@@ -38,6 +38,7 @@ | |||
"country-emoji": "^1.5.0", | |||
"dotenv": "^8.2.0", | |||
"express": "^4.17.1", | |||
"firebase": "^7.13.2", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
partially fixed in #58 |
@danbilokha What we've talked about in "offline onverstion" is to make sending notifications kinda scheduled process. |
Going to get back tomorrow. |
@danbilokha I'm done with reviewing. |
} | ||
} | ||
}; | ||
import {getContinentsInlineKeyboard} from '../utils/keyboard'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what are the code style rules? single quotes or double quotes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bomba-Rocketa!
@@ -28,7 +28,9 @@ export enum UserMessages { | |||
CountriesData = 'Countries data 🌍', | |||
AvailableCountries = 'Countries we track', | |||
GetAdvicesHowToBehave = 'Advice how not to 😷', | |||
MySubscriptions = 'My subscriptions 💌', | |||
SubscriptionManager = 'Subscriptions 💌', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like. The way u add messages. It always goes with a nice smile!
👍
@@ -2,7 +2,8 @@ import {TelegramChat} from "../../bots/telegram/models"; | |||
import {getAvailableCountries} from "./covid19"; | |||
import {Country} from "../../models/country.models"; | |||
import {getTelegramUserSubscriptions, setTelegramSubscription} from "../../bots/telegram/services/storage"; | |||
import {SubscriptionType} from "../../models/subscription.models"; | |||
import {SubscriptionType, UserSubscription} from "../../models/subscription.models"; | |||
import {SubscriptionStorage} from "../../models/storage.models"; | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
INGNORE IT
WAS FIXED IN A FUTURE COMMIT
I'd rename the file to be subscription.
Since from my point of view, in this folder and layer as well. we are trying to represent core objects of our application.
So naming it subscription would make it more consistent in terms of understanding the domain
let userSubscriptionNotifications: Array<UserSubscriptionNotification> = []; | ||
|
||
userSubscriptionsOn | ||
.filter(subscription => subscription.active !== false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm really new to fire base. But I'd recommend to move this filter to the firebase request.
I'm also wondering what for do we store inactive subscriptions?
userSubscriptionsOn | ||
.filter(subscription => subscription.active !== false) | ||
.forEach((subscription: Subscription) => { | ||
if (subscription.type === SubscriptionType.Country) { // TODO: Take into account timezone |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This if seems like also could be moved up to the firebase reques
|
||
const subscriptionCountryLastInfo: CountrySituationInfo = userSubscriptionCountry[userSubscriptionCountry.length - 1]; | ||
|
||
const subscriptionCountryLastUpdate = subscriptionCountryLastInfo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any native way that js could save data to string representation and then parse it back.
I mean without all that noise with dashes and parsing ints?
getUnsubscribeMessageInlineKeyboard( | ||
userSubscription | ||
.subscriptionsOn | ||
.filter(v => v.active !== false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Filter goes second time.
Just as a reminder from me to follow DRY 🎗️
@@ -34,26 +39,35 @@ function runTelegramBot(app: Express, ngRokUrl: string) { | |||
registry.setBot(bot); // TODO: DO IT COOLER | |||
registry | |||
.registerMessageHandler(UserRegExps.Start, startResponse) | |||
// Feature: Countries / Country |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah it's becoming really huge. Good idea for separating it by features 💯
@@ -32,6 +33,45 @@ export const getAfterCountryResponseInlineKeyboard = (country: string): unknown | |||
return ik.build(); | |||
}; | |||
|
|||
export const getSubscriptionMessageInlineKeyboard = (): unknown => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's was really cool to see! 💯 🎖️
server/src/bots/telegram/index.ts
Outdated
logger.log('info', message); | ||
logger.log('info', args); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be better to log message with args as a single object. Just to keep each log record synchronized
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
export const getConcreteUserSubscriptions = ( | ||
chatId: number, allUsersSubscriptions: SubscriptionStorage | ||
): UserSubscription => { | ||
const userSubscriptionKey = Object.keys(allUsersSubscriptions) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible for us to ask from firebase just a user's subscriptions only and not all of them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
deleted
No description provided.