Skip to content
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

Merged
merged 16 commits into from
Apr 12, 2020
Merged

Feature/life notification #60

merged 16 commits into from
Apr 12, 2020

Conversation

danemesis
Copy link
Owner

No description provided.

@danemesis danemesis requested a review from Proladge April 9, 2020 17:53
@danemesis
Copy link
Owner Author

TODO: Handle mapping of user subscription input from inline keyboard to our subscription strategy

@danemesis danemesis self-assigned this Apr 9, 2020
@danemesis danemesis added this to the release 2 milestone Apr 9, 2020
@danemesis danemesis linked an issue Apr 9, 2020 that may be closed by this pull request
Copy link
Collaborator

@Proladge Proladge left a 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;
Copy link
Collaborator

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. 🇺🇬

Copy link
Collaborator

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....

Copy link
Owner Author

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';
Copy link
Collaborator

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",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@danemesis danemesis marked this pull request as draft April 10, 2020 04:39
@danemesis danemesis changed the title [WIP] Feature/life notification Feature/life notification Apr 11, 2020
@danemesis danemesis marked this pull request as ready for review April 11, 2020 18:11
@danemesis
Copy link
Owner Author

partially fixed in #58

@Proladge
Copy link
Collaborator

Proladge commented Apr 11, 2020

@danbilokha What we've talked about in "offline onverstion" is to make sending notifications kinda scheduled process.
I suppose this could be helpful. And pretty simple to reuse
https://www.npmjs.com/package/node-schedule

@Proladge
Copy link
Collaborator

Going to get back tomorrow.
To do a second round of reviewing.
It's really huge! 🚢

@Proladge
Copy link
Collaborator

@danbilokha I'm done with reviewing.
🔥 base 💯
Ready to come back once u react on the comments

@danemesis danemesis requested a review from jmelnych April 12, 2020 11:12
}
}
};
import {getContinentsInlineKeyboard} from '../utils/keyboard';
Copy link
Collaborator

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?

Copy link
Collaborator

@Proladge Proladge left a 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 💌',
Copy link
Collaborator

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";

Copy link
Collaborator

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)
Copy link
Collaborator

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
Copy link
Collaborator

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
Copy link
Collaborator

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)
Copy link
Collaborator

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
Copy link
Collaborator

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 => {
Copy link
Collaborator

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! 💯 🎖️

Comment on lines 89 to 90
logger.log('info', message);
logger.log('info', args);
Copy link
Collaborator

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

Copy link
Owner Author

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)
Copy link
Collaborator

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?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deleted

@danemesis danemesis merged commit 9ee436c into master Apr 12, 2020
@danemesis danemesis deleted the feature/life-notification branch April 12, 2020 12:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants