1
0
Fork 0
mirror of https://github.com/muerwre/vk-tg-bot.git synced 2025-04-24 22:46:41 +07:00

#5 better user name computation

This commit is contained in:
Fedor Katurov 2021-05-12 16:56:58 +07:00
parent df4b5d8dca
commit b04be794af

View file

@ -9,6 +9,7 @@ import {
InlineKeyboardMarkup, InlineKeyboardMarkup,
Message, Message,
Update, Update,
User,
} from "typegram"; } from "typegram";
import { keys } from "ramda"; import { keys } from "ramda";
import { extractURLs } from "../../../utils/extract"; import { extractURLs } from "../../../utils/extract";
@ -332,7 +333,7 @@ export class PostNewHandler extends VkEventHandler<Fields, Values> {
markup markup
); );
const who = ctx.update?.callback_query?.from?.username || "someone"; const who = this.getNameFromContext(ctx?.update?.callback_query?.from);
const short = post.text.slice(0, 10); const short = post.text.slice(0, 10);
logger.info( logger.info(
@ -410,4 +411,13 @@ export class PostNewHandler extends VkEventHandler<Fields, Values> {
*/ */
generateVkPostUrl = (postId?: number) => generateVkPostUrl = (postId?: number) =>
`https://vk.com/wall-${this.group.id}_${postId}`; `https://vk.com/wall-${this.group.id}_${postId}`;
/**
* Returns fullname from user of update callback
*/
getNameFromContext = (from: User): string =>
[from?.first_name, from?.last_name]
.filter((el) => el)
.join(" ")
.trim() || "someone";
} }