Skip to content

Commit

Permalink
fix(util/index): fix arg type & fn calls
Browse files Browse the repository at this point in the history
Typescript compilers in newer versions complain about when
calling functions with named parameters, there is no argument
interface for the deleteMessage method in Telegraf framework
so I changed it, and there's a telegram argument with the
wrong type.

```
util/index.ts:283:20 - error TS2554: Expected 2 arguments, but got 1.

283     await telegram.deleteMessage({chat_id: channel!, message_id: Number(order.tg_channel_message1!)});
                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  node_modules/telegraf/typings/telegram.d.ts:317:44
    317     deleteMessage(chatId: number | string, messageId: number): Promise<true>;
                                                   ~~~~~~~~~~~~~~~~~
    An argument for 'messageId' was not provided.

Found 1 error in util/index.ts:283
```
  • Loading branch information
Mersho committed Nov 1, 2023
1 parent c411bfe commit 476a801
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { IOrder } from "../models/order";
import { UserDocument } from "../models/user";
import { IFiatCurrencies, IFiat } from "./fiatModel";
import { ILanguage, ILanguages } from "./languagesModel";
import { Telegram } from "telegraf/typings/core/types/typegram";
import axios from "axios";
import fiatJson from './fiat.json';
import languagesJson from './languages.json';
Expand Down Expand Up @@ -230,9 +229,9 @@ const secondsToTime = (secs: number) => {
};
};

const isGroupAdmin = async (groupId: string, user: UserDocument, telegram: Telegram) => {
const isGroupAdmin = async (groupId: string, user: UserDocument, telegram: MainContext['telegram']) => {
try {
const member = await telegram.getChatMember({chat_id: groupId, user_id: Number(user.tg_id)});
const member = await telegram.getChatMember(groupId, Number(user.tg_id));
if (
member &&
(member.status === 'creator' || member.status === 'administrator')
Expand Down Expand Up @@ -261,9 +260,11 @@ const isGroupAdmin = async (groupId: string, user: UserDocument, telegram: Teleg
}
};

const deleteOrderFromChannel = async (order: IOrder, telegram: Telegram) => {
const deleteOrderFromChannel = async (order: IOrder, telegram: MainContext['telegram']) => {
try {
let channel = process.env.CHANNEL;
if (channel === undefined) throw Error("CHANNEL not found, please check .env file")
if (order.tg_channel_message1 === undefined) throw Error("order.tg_channel_message1 was not found in DB")
if (order.community_id) {
const community = await Community.findOne({ _id: order.community_id });
if (!community) {
Expand All @@ -279,7 +280,7 @@ const deleteOrderFromChannel = async (order: IOrder, telegram: Telegram) => {
}
}
}
await telegram.deleteMessage({chat_id: channel!, message_id: Number(order.tg_channel_message1!)});
await telegram.deleteMessage(channel, Number(order.tg_channel_message1));
} catch (error) {
logger.error(error);
}
Expand Down

0 comments on commit 476a801

Please sign in to comment.