Comparing version 1.7.0 to 1.7.1
@@ -1,2 +0,2 @@ | ||
import { IMessage, ContentTypes, ISendPhotoOptions, IOptions, MessageCreator, Keyboard, IWebhookConfig, IDeleteWebhookConfig, IUser, IAnswerCallbackQueryOptions, ISendVideoOptions, Video, Photo, Audio, ISendAudioOptions, IFile, IForwardMessageOptions, ICopyMessageOptions, IMessageId, Document, ISendDocumentOptions, ISendAnimationOptions, Voice, ISendVoiceOptions, ISendVideoNoteOptions } from '..'; | ||
import { Audio, ContentTypes, Document, IAnswerCallbackQueryOptions, ICopyMessageOptions, IDeleteWebhookConfig, IFile, IForwardMessageOptions, IMessage, IMessageId, InputSupportedMedia, IOptions, ISendAnimationOptions, ISendAudioOptions, ISendDocumentOptions, ISendMediaGroupOptions, ISendPhotoOptions, ISendVideoNoteOptions, ISendVideoOptions, ISendVoiceOptions, IUser, IWebhookConfig, Keyboard, MessageCreator, Photo, Video, Voice } from '..'; | ||
import { Animation, VideoNote } from './Media'; | ||
@@ -10,2 +10,3 @@ export declare class Api { | ||
private buildFormData; | ||
private buildAttachFormData; | ||
private static saveMediaFileId; | ||
@@ -15,3 +16,3 @@ getMe(): Promise<IUser>; | ||
deleteWebhook(config?: IDeleteWebhookConfig): Promise<boolean>; | ||
send(chatId: string | number, content: MessageCreator | ContentTypes, keyboard?: Keyboard | null, moreOptions?: IOptions): Promise<IMessage>; | ||
send(chatId: string | number, content: MessageCreator | ContentTypes, keyboard?: Keyboard | null, moreOptions?: IOptions): Promise<IMessage | IMessage[]>; | ||
sendPhoto(chatId: string | number, photo: Photo, keyboard?: Keyboard | null, moreOptions?: ISendPhotoOptions): Promise<IMessage>; | ||
@@ -24,2 +25,3 @@ sendVideo(chatId: string | number, video: Video, keyboard?: Keyboard | null, moreOptions?: ISendVideoOptions): Promise<IMessage>; | ||
sendAnimation(chatId: string | number, animation: Animation, keyboard?: Keyboard | null, moreOptions?: ISendAnimationOptions): Promise<IMessage>; | ||
sendMediaGroup(chatId: string | number, mediaGroup: InputSupportedMedia[], moreOptions?: ISendMediaGroupOptions): Promise<IMessage[]>; | ||
answerCallbackQuery(callback_query_id: string, moreOptions?: IAnswerCallbackQueryOptions): Promise<boolean>; | ||
@@ -26,0 +28,0 @@ alert(callback_query_id: string, text: string, moreOptions?: IAnswerCallbackQueryOptions): Promise<boolean>; |
@@ -58,2 +58,12 @@ "use strict"; | ||
} | ||
buildAttachFormData(config) { | ||
const formData = new FormData(); | ||
Object.keys(config).forEach((key) => { | ||
const data = config[key]; | ||
if (!data) | ||
return; | ||
formData.append(key, typeof data === 'object' ? JSON.stringify(data) : data); | ||
}); | ||
return formData; | ||
} | ||
static saveMediaFileId(path, mediaKey, message) { | ||
@@ -102,2 +112,4 @@ if (!MediaCache_1.mediaCache.getMediaFileId(path)) { | ||
return this.sendVoice(chatId, content, keyboard, moreOptions); | ||
else if (content instanceof __1.MediaGroup) | ||
return this.sendMediaGroup(chatId, content.mediaGroup, moreOptions); | ||
else | ||
@@ -187,2 +199,33 @@ throw (0, logger_1.error)("Media file type is not defined. Don't use Media class, use Photo, Video class instead"); | ||
} | ||
async sendMediaGroup(chatId, mediaGroup, moreOptions = {}) { | ||
const formData = this.buildAttachFormData({ | ||
chat_id: chatId, | ||
media: mediaGroup.map((media, index) => { | ||
return { | ||
type: media.type, | ||
media: MediaCache_1.mediaCache.getMediaFileId(media.media) || `attach://${index}`, | ||
...(media.thumb | ||
? { thumb: MediaCache_1.mediaCache.getMediaFileId(media.thumb.media) || `attach://${index}_thumb` } | ||
: {}), | ||
...(media instanceof __1.Video ? media.resolution : {}), | ||
...(media.options || {}), | ||
}; | ||
}), | ||
...moreOptions, | ||
}); | ||
mediaGroup.forEach((media, index) => { | ||
if (!MediaCache_1.mediaCache.getMediaFileId(media.media)) | ||
Api.appendMediaToFormData(formData, index.toString(), media); | ||
if (media.thumb) { | ||
if (!MediaCache_1.mediaCache.getMediaFileId(media.thumb.media)) | ||
Api.appendMediaToFormData(formData, `${index.toString()}_thumb`, media.thumb); | ||
} | ||
}); | ||
const sentMessages = await this.callApi('sendMediaGroup', formData); | ||
for (const sentMessage of sentMessages) { | ||
const media = mediaGroup[sentMessages.indexOf(sentMessage)]; | ||
Api.saveMediaFileId(media.media, media.type, sentMessage); | ||
} | ||
return sentMessages; | ||
} | ||
answerCallbackQuery(callback_query_id, moreOptions = {}) { | ||
@@ -189,0 +232,0 @@ return this.callApi('answerCallbackQuery', { |
@@ -9,3 +9,3 @@ import { ISendOptions, IMessage, IUpdate, ContentTypes, Keyboard, IAnswerCallbackQueryOptions, IFile, IForwardMessageOptions, ICopyMessageOptions } from '../..'; | ||
constructor(token: string, update: IUpdate); | ||
send(content: MessageCreator | ContentTypes, keyboard?: Keyboard | null, moreOptions?: ISendOptions): Promise<IMessage>; | ||
send(content: MessageCreator | ContentTypes, keyboard?: Keyboard | null, moreOptions?: ISendOptions): Promise<IMessage | IMessage[]>; | ||
alert(text: string, moreOptions?: IAnswerCallbackQueryOptions): Promise<boolean>; | ||
@@ -12,0 +12,0 @@ toast(text: string, moreOptions?: IAnswerCallbackQueryOptions): Promise<boolean>; |
import { Video } from './Video'; | ||
import { MediaFileTypes } from '../../types'; | ||
export declare class Animation extends Video { | ||
type: MediaFileTypes; | ||
} |
@@ -6,4 +6,8 @@ "use strict"; | ||
class Animation extends Video_1.Video { | ||
constructor() { | ||
super(...arguments); | ||
this.type = 'animation'; | ||
} | ||
} | ||
exports.Animation = Animation; | ||
//# sourceMappingURL=Animation.js.map |
import { Media } from './Media'; | ||
import { MediaFileTypes } from '../../types'; | ||
export declare class Audio extends Media { | ||
type: MediaFileTypes; | ||
} |
@@ -6,4 +6,8 @@ "use strict"; | ||
class Audio extends Media_1.Media { | ||
constructor() { | ||
super(...arguments); | ||
this.type = 'audio'; | ||
} | ||
} | ||
exports.Audio = Audio; | ||
//# sourceMappingURL=Audio.js.map |
import { Media } from './Media'; | ||
import { MediaFileTypes } from '../../types'; | ||
export declare class Document extends Media { | ||
type: MediaFileTypes; | ||
} |
@@ -6,4 +6,8 @@ "use strict"; | ||
class Document extends Media_1.Media { | ||
constructor() { | ||
super(...arguments); | ||
this.type = 'document'; | ||
} | ||
} | ||
exports.Document = Document; | ||
//# sourceMappingURL=Document.js.map |
@@ -10,1 +10,2 @@ export * from './Photo'; | ||
export * from './Animation'; | ||
export * from './MediaGroup'; |
@@ -26,2 +26,3 @@ "use strict"; | ||
__exportStar(require("./Animation"), exports); | ||
__exportStar(require("./MediaGroup"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
import { MediaPassTypes } from '../../types'; | ||
import { MediaFileTypes, MediaPassTypes } from '../../types'; | ||
import { Thumb } from './Thumb'; | ||
@@ -6,5 +6,7 @@ export declare class Media { | ||
media: string; | ||
readonly options?: any; | ||
type: MediaFileTypes; | ||
thumb?: Thumb; | ||
constructor(passType: MediaPassTypes, media: string); | ||
constructor(passType: MediaPassTypes, media: string, options?: any); | ||
setThumb(thumb: Thumb): this; | ||
} |
@@ -5,5 +5,6 @@ "use strict"; | ||
class Media { | ||
constructor(passType, media) { | ||
constructor(passType, media, options) { | ||
this.passType = passType; | ||
this.media = media; | ||
this.options = options; | ||
} | ||
@@ -10,0 +11,0 @@ setThumb(thumb) { |
import { Media } from './Media'; | ||
import { MediaFileTypes } from '../../types'; | ||
export declare class Photo extends Media { | ||
type: MediaFileTypes; | ||
} |
@@ -6,4 +6,8 @@ "use strict"; | ||
class Photo extends Media_1.Media { | ||
constructor() { | ||
super(...arguments); | ||
this.type = 'photo'; | ||
} | ||
} | ||
exports.Photo = Photo; | ||
//# sourceMappingURL=Photo.js.map |
import { Media } from './Media'; | ||
import { IResolution } from '../../types'; | ||
import { IResolution, MediaFileTypes } from '../../types'; | ||
export declare class Video extends Media { | ||
type: MediaFileTypes; | ||
resolution: IResolution; | ||
setResolution(width?: number | null, height?: number | null): this; | ||
} |
@@ -8,2 +8,3 @@ "use strict"; | ||
super(...arguments); | ||
this.type = 'video'; | ||
this.resolution = { width: 1920, height: 1080 }; | ||
@@ -10,0 +11,0 @@ } |
import { Media } from './Media'; | ||
import { MediaFileTypes } from '../../types'; | ||
export declare class VideoNote extends Media { | ||
type: MediaFileTypes; | ||
} |
@@ -6,4 +6,8 @@ "use strict"; | ||
class VideoNote extends Media_1.Media { | ||
constructor() { | ||
super(...arguments); | ||
this.type = 'video_note'; | ||
} | ||
} | ||
exports.VideoNote = VideoNote; | ||
//# sourceMappingURL=VideoNote.js.map |
import { Media } from './Media'; | ||
import { MediaFileTypes } from '../../types'; | ||
export declare class Voice extends Media { | ||
type: MediaFileTypes; | ||
} |
@@ -6,4 +6,8 @@ "use strict"; | ||
class Voice extends Media_1.Media { | ||
constructor() { | ||
super(...arguments); | ||
this.type = 'voice'; | ||
} | ||
} | ||
exports.Voice = Voice; | ||
//# sourceMappingURL=Voice.js.map |
import { IMessageEntity } from './update.types'; | ||
import { ReplyMarkup } from './keyboard.types'; | ||
import { Thumb } from '../classes'; | ||
import { InputMediaTypes } from './media.types'; | ||
export declare type IOptions = ISendOptions | ISendPhotoOptions | ISendVideoOptions; | ||
@@ -19,2 +20,12 @@ export declare type ParseModes = 'HTML' | 'Markdown' | 'MarkdownV2'; | ||
} | ||
export interface ISendMediaGroupFetchOptions extends ISendMediaGroupOptions { | ||
chat_id: number | string; | ||
media: InputMediaTypes[]; | ||
} | ||
export interface ISendMediaGroupOptions { | ||
disable_notification?: boolean; | ||
protect_content?: boolean; | ||
reply_to_message_id?: number; | ||
allow_sending_without_reply?: boolean; | ||
} | ||
export interface ISendPhotoFetchOptions extends ISendPhotoOptions { | ||
@@ -21,0 +32,0 @@ chat_id: number | string; |
@@ -0,2 +1,7 @@ | ||
import { ParseModes } from './api.types'; | ||
import { IMessageEntity } from './update.types'; | ||
import { Audio, Document, Photo, Video } from '../classes'; | ||
export declare type MediaFileTypes = 'photo' | 'video' | 'thumb' | 'audio' | 'document' | 'animation' | 'voice' | 'video_note'; | ||
export declare type InputMediaTypes = IInputMediaAudio | IInputMediaDocument | IInputMediaPhoto | IInputMediaVideo; | ||
export declare type InputSupportedMedia = Audio | Document | Photo | Video; | ||
export declare type MediaPassTypes = 'url' | 'path'; | ||
@@ -7,1 +12,30 @@ export interface IResolution { | ||
} | ||
export interface IInputMediaDefault { | ||
type: 'audio' | 'video' | 'photo' | 'document'; | ||
media: string; | ||
caption?: string; | ||
parse_mode?: ParseModes; | ||
caption_entities?: IMessageEntity[]; | ||
} | ||
export interface IInputMediaAudio extends IInputMediaDefault { | ||
type: 'audio'; | ||
thumb?: string; | ||
duration?: number; | ||
performer?: string; | ||
title?: string; | ||
} | ||
export interface IInputMediaDocument extends IInputMediaDefault { | ||
type: 'document'; | ||
thumb?: string; | ||
} | ||
export interface IInputMediaPhoto extends IInputMediaDefault { | ||
type: 'photo'; | ||
} | ||
export interface IInputMediaVideo extends IInputMediaDefault { | ||
type: 'video'; | ||
thumb?: string; | ||
width?: number; | ||
height?: number; | ||
duration?: number; | ||
supports_streaming?: boolean; | ||
} |
{ | ||
"name": "nestgram", | ||
"description": "Framework for working with Telegram Bot API on TypeScript like Nest.js", | ||
"version": "1.7.0", | ||
"version": "1.7.1", | ||
"main": "dist/index.js", | ||
@@ -51,5 +51,4 @@ "types": "dist/index.d.ts", | ||
"form-data": "^4.0.0", | ||
"mongoose": "^6.3.5", | ||
"reflect-metadata": "^0.1.13" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
181525
5
177
2477
- Removedmongoose@^6.3.5
- Removed@aws-crypto/sha256-browser@5.2.0(transitive)
- Removed@aws-crypto/sha256-js@5.2.0(transitive)
- Removed@aws-crypto/supports-web-crypto@5.2.0(transitive)
- Removed@aws-crypto/util@5.2.0(transitive)
- Removed@aws-sdk/client-cognito-identity@3.685.0(transitive)
- Removed@aws-sdk/client-sso@3.682.0(transitive)
- Removed@aws-sdk/client-sso-oidc@3.682.0(transitive)
- Removed@aws-sdk/client-sts@3.682.0(transitive)
- Removed@aws-sdk/core@3.679.0(transitive)
- Removed@aws-sdk/credential-provider-cognito-identity@3.685.0(transitive)
- Removed@aws-sdk/credential-provider-env@3.679.0(transitive)
- Removed@aws-sdk/credential-provider-http@3.679.0(transitive)
- Removed@aws-sdk/credential-provider-ini@3.682.0(transitive)
- Removed@aws-sdk/credential-provider-node@3.682.0(transitive)
- Removed@aws-sdk/credential-provider-process@3.679.0(transitive)
- Removed@aws-sdk/credential-provider-sso@3.682.0(transitive)
- Removed@aws-sdk/credential-provider-web-identity@3.679.0(transitive)
- Removed@aws-sdk/credential-providers@3.685.0(transitive)
- Removed@aws-sdk/middleware-host-header@3.679.0(transitive)
- Removed@aws-sdk/middleware-logger@3.679.0(transitive)
- Removed@aws-sdk/middleware-recursion-detection@3.679.0(transitive)
- Removed@aws-sdk/middleware-user-agent@3.682.0(transitive)
- Removed@aws-sdk/region-config-resolver@3.679.0(transitive)
- Removed@aws-sdk/token-providers@3.679.0(transitive)
- Removed@aws-sdk/types@3.679.0(transitive)
- Removed@aws-sdk/util-endpoints@3.679.0(transitive)
- Removed@aws-sdk/util-locate-window@3.679.0(transitive)
- Removed@aws-sdk/util-user-agent-browser@3.679.0(transitive)
- Removed@aws-sdk/util-user-agent-node@3.682.0(transitive)
- Removed@mongodb-js/saslprep@1.1.9(transitive)
- Removed@smithy/abort-controller@3.1.6(transitive)
- Removed@smithy/config-resolver@3.0.10(transitive)
- Removed@smithy/core@2.5.1(transitive)
- Removed@smithy/credential-provider-imds@3.2.5(transitive)
- Removed@smithy/fetch-http-handler@3.2.94.0.0(transitive)
- Removed@smithy/hash-node@3.0.8(transitive)
- Removed@smithy/invalid-dependency@3.0.8(transitive)
- Removed@smithy/is-array-buffer@2.2.03.0.0(transitive)
- Removed@smithy/middleware-content-length@3.0.10(transitive)
- Removed@smithy/middleware-endpoint@3.2.1(transitive)
- Removed@smithy/middleware-retry@3.0.25(transitive)
- Removed@smithy/middleware-serde@3.0.8(transitive)
- Removed@smithy/middleware-stack@3.0.8(transitive)
- Removed@smithy/node-config-provider@3.1.9(transitive)
- Removed@smithy/node-http-handler@3.2.5(transitive)
- Removed@smithy/property-provider@3.1.8(transitive)
- Removed@smithy/protocol-http@4.1.5(transitive)
- Removed@smithy/querystring-builder@3.0.8(transitive)
- Removed@smithy/querystring-parser@3.0.8(transitive)
- Removed@smithy/service-error-classification@3.0.8(transitive)
- Removed@smithy/shared-ini-file-loader@3.1.9(transitive)
- Removed@smithy/signature-v4@4.2.1(transitive)
- Removed@smithy/smithy-client@3.4.2(transitive)
- Removed@smithy/types@3.6.0(transitive)
- Removed@smithy/url-parser@3.0.8(transitive)
- Removed@smithy/util-base64@3.0.0(transitive)
- Removed@smithy/util-body-length-browser@3.0.0(transitive)
- Removed@smithy/util-body-length-node@3.0.0(transitive)
- Removed@smithy/util-buffer-from@2.2.03.0.0(transitive)
- Removed@smithy/util-config-provider@3.0.0(transitive)
- Removed@smithy/util-defaults-mode-browser@3.0.25(transitive)
- Removed@smithy/util-defaults-mode-node@3.0.25(transitive)
- Removed@smithy/util-endpoints@2.1.4(transitive)
- Removed@smithy/util-hex-encoding@3.0.0(transitive)
- Removed@smithy/util-middleware@3.0.8(transitive)
- Removed@smithy/util-retry@3.0.8(transitive)
- Removed@smithy/util-stream@3.2.1(transitive)
- Removed@smithy/util-uri-escape@3.0.0(transitive)
- Removed@smithy/util-utf8@2.3.03.0.0(transitive)
- Removed@types/node@22.8.7(transitive)
- Removed@types/webidl-conversions@7.0.3(transitive)
- Removed@types/whatwg-url@8.2.2(transitive)
- Removedbase64-js@1.5.1(transitive)
- Removedbowser@2.11.0(transitive)
- Removedbson@4.7.2(transitive)
- Removedbuffer@5.7.1(transitive)
- Removeddebug@4.3.7(transitive)
- Removedfast-xml-parser@4.4.1(transitive)
- Removedieee754@1.2.1(transitive)
- Removedip-address@9.0.5(transitive)
- Removedjsbn@1.1.0(transitive)
- Removedkareem@2.5.1(transitive)
- Removedmemory-pager@1.5.0(transitive)
- Removedmongodb@4.17.2(transitive)
- Removedmongodb-connection-string-url@2.6.0(transitive)
- Removedmongoose@6.13.3(transitive)
- Removedmpath@0.9.0(transitive)
- Removedmquery@4.0.3(transitive)
- Removedms@2.1.3(transitive)
- Removedpunycode@2.3.1(transitive)
- Removedsift@16.0.1(transitive)
- Removedsmart-buffer@4.2.0(transitive)
- Removedsocks@2.8.3(transitive)
- Removedsparse-bitfield@3.0.3(transitive)
- Removedsprintf-js@1.1.3(transitive)
- Removedstrnum@1.0.5(transitive)
- Removedtr46@3.0.0(transitive)
- Removedtslib@2.8.1(transitive)
- Removedundici-types@6.19.8(transitive)
- Removeduuid@9.0.1(transitive)
- Removedwebidl-conversions@7.0.0(transitive)
- Removedwhatwg-url@11.0.0(transitive)