Comparing version 1.0.0-alpha.0 to 1.0.0-alpha.1
@@ -22,3 +22,2 @@ "use strict"; | ||
apiHeaders: { | ||
// TODO: add github link and version info | ||
'User-Agent': `${package_json_1.name}/${package_json_1.version} (+${package_json_1.repository.url})` | ||
@@ -43,3 +42,3 @@ }, | ||
// @ts-expect-error | ||
this.api = new Proxy(() => null, { | ||
this.api = new Proxy(() => { }, { | ||
// redirect api.method(params) to api(method, params) | ||
@@ -58,4 +57,2 @@ get: (_target, method) => (params) => { | ||
}; | ||
const abortController = new abort_controller_1.default(); | ||
const timeout = setTimeout(() => abortController.abort(), apiTimeout); | ||
const methodUrls = { | ||
@@ -86,5 +83,5 @@ getMe: '/getMe', | ||
// FIXME: cringe | ||
const urlObj = new URL(url); | ||
urlObj.searchParams.append(param, String(params[param])); | ||
url = url.replace(/\?.*$/, '') + urlObj.search; | ||
const urlObject = new URL(url); | ||
urlObject.searchParams.append(param, String(params[param])); | ||
url = url.replace(/\?.*$/, '') + urlObject.search; | ||
} | ||
@@ -104,33 +101,34 @@ } | ||
}) | ||
: httpMethod === 'POST' | ||
: (httpMethod === 'POST' | ||
? JSON.stringify(params) | ||
: undefined; | ||
: undefined); | ||
debug(`[${method}] --> ${httpMethod} ${url}`); | ||
if (body) | ||
debug(`[${method}] Params: ${body}`); | ||
// request timeout | ||
const abortController = new abort_controller_1.default(); | ||
const timeout = setTimeout(() => abortController.abort(), apiTimeout); | ||
let response; | ||
try { | ||
debug(`[${method}] --> ${httpMethod} ${url}`); | ||
if (body) | ||
debug(`[${method}] Params: ${body}`); | ||
let response; | ||
try { | ||
response = await node_fetch_1.default(url, { | ||
method: httpMethod, | ||
signal: abortController.signal, | ||
agent, | ||
body, | ||
headers | ||
}); | ||
} | ||
catch (e) { | ||
debug(e); | ||
throw e; | ||
} | ||
const json = await response.json(); | ||
debug(`[${method}] Response:`, json); | ||
if (!json.error) | ||
return json; | ||
const { status, message } = json.error; | ||
throw new errors_1.ApiError({ status, message }); | ||
response = await node_fetch_1.default(url, { | ||
method: httpMethod, | ||
signal: abortController.signal, | ||
agent, | ||
body, | ||
headers | ||
}); | ||
} | ||
catch (error) { | ||
debug(error); | ||
throw error; | ||
} | ||
finally { | ||
clearTimeout(timeout); | ||
} | ||
const json = await response.json(); | ||
debug(`[${method}] Response:`, json); | ||
if (!json.error) | ||
return json; | ||
const { status, message } = json.error; | ||
throw new errors_1.ApiError({ status, message }); | ||
} | ||
@@ -137,0 +135,0 @@ }); |
@@ -1,12 +0,12 @@ | ||
export * from './SendMessage'; | ||
export * from './ForwardMessage'; | ||
export * from './EditMessage'; | ||
export * from './SendUiState'; | ||
export * from './DeleteMessage'; | ||
export * from './KickFromGroup'; | ||
export * from './ChangeGroupAvatar'; | ||
export * from './ChangeGroupDescription'; | ||
export * from './ChangeGroupTitle'; | ||
export * from './DeleteGroupAvatar'; | ||
export * from './SendContainerMessage'; | ||
export * from './EditContainerMessage'; | ||
export * from './send-message'; | ||
export * from './forward-message'; | ||
export * from './edit-message'; | ||
export * from './send-ui-state'; | ||
export * from './delete-message'; | ||
export * from './kick-from-group'; | ||
export * from './change-group-avatar'; | ||
export * from './change-group-description'; | ||
export * from './change-group-title'; | ||
export * from './delete-group-avatar'; | ||
export * from './send-container-message'; | ||
export * from './edit-container-message'; |
@@ -13,13 +13,13 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__exportStar(require("./SendMessage"), exports); | ||
__exportStar(require("./ForwardMessage"), exports); | ||
__exportStar(require("./EditMessage"), exports); | ||
__exportStar(require("./SendUiState"), exports); | ||
__exportStar(require("./DeleteMessage"), exports); | ||
__exportStar(require("./KickFromGroup"), exports); | ||
__exportStar(require("./ChangeGroupAvatar"), exports); | ||
__exportStar(require("./ChangeGroupDescription"), exports); | ||
__exportStar(require("./ChangeGroupTitle"), exports); | ||
__exportStar(require("./DeleteGroupAvatar"), exports); | ||
__exportStar(require("./SendContainerMessage"), exports); | ||
__exportStar(require("./EditContainerMessage"), exports); | ||
__exportStar(require("./send-message"), exports); | ||
__exportStar(require("./forward-message"), exports); | ||
__exportStar(require("./edit-message"), exports); | ||
__exportStar(require("./send-ui-state"), exports); | ||
__exportStar(require("./delete-message"), exports); | ||
__exportStar(require("./kick-from-group"), exports); | ||
__exportStar(require("./change-group-avatar"), exports); | ||
__exportStar(require("./change-group-description"), exports); | ||
__exportStar(require("./change-group-title"), exports); | ||
__exportStar(require("./delete-group-avatar"), exports); | ||
__exportStar(require("./send-container-message"), exports); | ||
__exportStar(require("./edit-container-message"), exports); |
export * from './commands'; | ||
export * from './methods'; | ||
export * from './ApiMethods'; | ||
export * from './ApiRequestParams'; | ||
export * from './api-methods'; | ||
export * from './api-request-params'; |
@@ -15,3 +15,3 @@ "use strict"; | ||
__exportStar(require("./methods"), exports); | ||
__exportStar(require("./ApiMethods"), exports); | ||
__exportStar(require("./ApiRequestParams"), exports); | ||
__exportStar(require("./api-methods"), exports); | ||
__exportStar(require("./api-request-params"), exports); |
@@ -1,6 +0,6 @@ | ||
export * from './getMe'; | ||
export * from './getChannelInfo'; | ||
export * from './getChannelAdmins'; | ||
export * from './getWebhookInfo'; | ||
export * from './setWebhook'; | ||
export * from './deleteWebhook'; | ||
export * from './get-me'; | ||
export * from './get-channel-info'; | ||
export * from './get-channel-admins'; | ||
export * from './get-webhook-info'; | ||
export * from './set-webhook'; | ||
export * from './delete-webhook'; |
@@ -13,7 +13,7 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__exportStar(require("./getMe"), exports); | ||
__exportStar(require("./getChannelInfo"), exports); | ||
__exportStar(require("./getChannelAdmins"), exports); | ||
__exportStar(require("./getWebhookInfo"), exports); | ||
__exportStar(require("./setWebhook"), exports); | ||
__exportStar(require("./deleteWebhook"), exports); | ||
__exportStar(require("./get-me"), exports); | ||
__exportStar(require("./get-channel-info"), exports); | ||
__exportStar(require("./get-channel-admins"), exports); | ||
__exportStar(require("./get-webhook-info"), exports); | ||
__exportStar(require("./set-webhook"), exports); | ||
__exportStar(require("./delete-webhook"), exports); |
export * from './context'; | ||
export * from './message'; | ||
export * from './kickInvite'; | ||
export * from './channelAdmin'; | ||
export * from './newChannelSubscriber'; | ||
export * from './channelPermissions'; | ||
export * from './inlineCommandSelected'; | ||
export * from './messageIdAssigned'; | ||
export * from './quickButtonSelected'; | ||
export * from './kick-invite'; | ||
export * from './channel-admin'; | ||
export * from './new-channel-subscriber'; | ||
export * from './channel-permissions'; | ||
export * from './inline-command-selected'; | ||
export * from './message-id-assigned'; | ||
export * from './quick-button-selected'; |
@@ -15,8 +15,8 @@ "use strict"; | ||
__exportStar(require("./message"), exports); | ||
__exportStar(require("./kickInvite"), exports); | ||
__exportStar(require("./channelAdmin"), exports); | ||
__exportStar(require("./newChannelSubscriber"), exports); | ||
__exportStar(require("./channelPermissions"), exports); | ||
__exportStar(require("./inlineCommandSelected"), exports); | ||
__exportStar(require("./messageIdAssigned"), exports); | ||
__exportStar(require("./quickButtonSelected"), exports); | ||
__exportStar(require("./kick-invite"), exports); | ||
__exportStar(require("./channel-admin"), exports); | ||
__exportStar(require("./new-channel-subscriber"), exports); | ||
__exportStar(require("./channel-permissions"), exports); | ||
__exportStar(require("./inline-command-selected"), exports); | ||
__exportStar(require("./message-id-assigned"), exports); | ||
__exportStar(require("./quick-button-selected"), exports); |
import { Context, ContextOptions } from './context'; | ||
import { SendMessageParams } from '../api'; | ||
import { MessageUpdate, Peer, MessageEditedUpdate, MediaType, RegisteredContact, UnregisteredContact } from '../interfaces'; | ||
import { Peer, Update } from '../interfaces'; | ||
import { PeerType, MessageForwardMetadata } from '../types'; | ||
import { Media, ImageMedia, VideoMedia, DocumentMedia, AudioMedia, ContactMedia } from '../structures'; | ||
import { Media, ImageMedia, VideoMedia, DocumentMedia, AudioMedia, ContactMedia, MediaType, MediaPayload, RegisteredContactPayload, UnregisteredContactPayload } from '../structures'; | ||
export interface MessageUpdate extends Update { | ||
type: 'Message'; | ||
messageId: string; | ||
sentAt: string; | ||
author: Peer; | ||
dialog: Peer; | ||
content: string; | ||
forwardMetadata?: { | ||
sender: Peer; | ||
}; | ||
media?: MediaPayload[]; | ||
likeCount?: number; | ||
repostCount?: number; | ||
viewCount?: number; | ||
channelPostAuthor?: Peer; | ||
replyToMessageId?: string; | ||
} | ||
export interface MessageEditedUpdate extends Update { | ||
type: 'MessageEdited'; | ||
messageId: string; | ||
author: Peer; | ||
dialog: Peer; | ||
content: string; | ||
} | ||
export declare type MessageContextPayload = MessageUpdate | MessageEditedUpdate; | ||
@@ -33,4 +57,4 @@ export declare type MessageContextType = MessageContextPayload['type']; | ||
getMedia(type: 'Audio'): AudioMedia[]; | ||
getMedia(type: 'RegisteredContact'): ContactMedia<RegisteredContact, 'RegisteredContact'>[]; | ||
getMedia(type: 'UnregisteredContact'): ContactMedia<UnregisteredContact, 'UnregisteredContact'>[]; | ||
getMedia(type: 'RegisteredContact'): ContactMedia<RegisteredContactPayload, 'RegisteredContact'>[]; | ||
getMedia(type: 'UnregisteredContact'): ContactMedia<UnregisteredContactPayload, 'UnregisteredContact'>[]; | ||
send(content: string | SendMessageParams, params?: Partial<SendMessageParams>): Promise<{}>; | ||
@@ -37,0 +61,0 @@ reply(content: string | SendMessageParams, params?: Partial<SendMessageParams>): Promise<{}>; |
@@ -11,3 +11,3 @@ "use strict"; | ||
this.media = 'media' in this.payload | ||
? this.payload.media.map(e => structures_1.Media.fromObject(e, this.aitu)) | ||
? this.payload.media.map(mediaPayload => structures_1.Media.fromObject(mediaPayload, this.aitu)) | ||
: []; | ||
@@ -67,3 +67,3 @@ } | ||
if (type) { | ||
return this.media.some(e => e.type === type); | ||
return this.media.some(media => media.type === type); | ||
} | ||
@@ -75,3 +75,3 @@ return this.media.length > 0; | ||
return this.media; | ||
return this.media.filter(e => e.type === type); | ||
return this.media.filter(media => media.type === type); | ||
} | ||
@@ -78,0 +78,0 @@ async send(content, params) { |
/// <reference types="node" /> | ||
import { Agent } from 'https'; | ||
import { UpdateType, PeerType, ChannelPermission, ApiResponse, ApiMethod } from './types'; | ||
import { UpdateType, PeerType, ApiResponse, ApiMethod } from './types'; | ||
import { ApiRequestParams, ApiMethods } from './api'; | ||
import { KeyboardBuilder } from './structures'; | ||
import { KeyboardBuilder, ReplyCommand, QuickButtonCommand, FormMessage, Form } from './structures'; | ||
export interface AituOptions { | ||
@@ -19,16 +19,2 @@ token: string; | ||
} | ||
export interface UserPeer extends Peer { | ||
type: 'USER'; | ||
username?: string; | ||
firstName?: string; | ||
lastName?: string; | ||
} | ||
export interface ServicePeer extends Peer { | ||
type: 'BOT'; | ||
name?: string; | ||
} | ||
export interface GroupPeer extends Peer { | ||
type: 'GROUP'; | ||
name?: string; | ||
} | ||
export interface ChannelPeer extends Peer { | ||
@@ -39,63 +25,2 @@ type: 'CHANNEL'; | ||
} | ||
export interface InputMedia { | ||
fileId: string; | ||
name: string; | ||
mediaType: 'IMAGE' | 'VIDEO' | 'AUDIO' | 'DOCUMENT'; | ||
} | ||
export interface BaseFileMedia { | ||
type: 'Image' | 'Video' | 'Audio' | 'Document' | 'Gif' | 'Music'; | ||
fileId: string; | ||
mimeType: string; | ||
name: string; | ||
size: number; | ||
} | ||
export interface Image extends BaseFileMedia { | ||
type: 'Image'; | ||
width: number; | ||
height: number; | ||
} | ||
export interface Gif extends BaseFileMedia { | ||
type: 'Gif'; | ||
width: number; | ||
height: number; | ||
duration: number; | ||
} | ||
export interface Music extends BaseFileMedia { | ||
type: 'Music'; | ||
duration: number; | ||
} | ||
export interface Video extends BaseFileMedia { | ||
type: 'Video'; | ||
width: number; | ||
height: number; | ||
duration: number; | ||
} | ||
export interface Audio extends BaseFileMedia { | ||
type: 'Audio'; | ||
} | ||
export interface Document extends BaseFileMedia { | ||
type: 'Document'; | ||
} | ||
export interface RegisteredContact { | ||
type: 'RegisteredContact'; | ||
user: User; | ||
} | ||
export interface UnregisteredContact { | ||
type: 'UnregisteredContact'; | ||
firstName?: string; | ||
lastName?: string; | ||
phoneNumber?: string; | ||
} | ||
export interface Avatar { | ||
full: Image; | ||
small: Image; | ||
} | ||
export interface User extends UnregisteredContact { | ||
userName: string; | ||
avatar: Avatar; | ||
} | ||
export declare type ContactMediaPayload = RegisteredContact | UnregisteredContact; | ||
export declare type ContactMediaType = ContactMediaPayload['type']; | ||
export declare type MediaPayload = Image | Video | Audio | Document | Gif | Music | RegisteredContact | UnregisteredContact; | ||
export declare type MediaType = MediaPayload['type']; | ||
export interface Update { | ||
@@ -105,113 +30,2 @@ updateId: string; | ||
} | ||
export interface MessageUpdate extends Update { | ||
type: 'Message'; | ||
messageId: string; | ||
sentAt: string; | ||
author: Peer; | ||
dialog: Peer; | ||
content: string; | ||
forwardMetadata?: { | ||
sender: Peer; | ||
}; | ||
media?: MediaPayload[]; | ||
likeCount?: number; | ||
repostCount?: number; | ||
viewCount?: number; | ||
channelPostAuthor?: Peer; | ||
replyToMessageId?: string; | ||
} | ||
export interface MessageEditedUpdate extends Update { | ||
type: 'MessageEdited'; | ||
messageId: string; | ||
author: Peer; | ||
dialog: Peer; | ||
content: string; | ||
} | ||
interface GroupStateUpdate extends Update { | ||
/** Group UUID */ | ||
groupId: string; | ||
} | ||
interface ChannelStateUpdate extends Update { | ||
/** Channel UUID */ | ||
channelId: string; | ||
} | ||
export interface InvitedToGroupUpdate extends GroupStateUpdate { | ||
type: 'InvitedToGroup'; | ||
} | ||
export interface KickedFromGroupUpdate extends GroupStateUpdate { | ||
type: 'KickedFromGroup'; | ||
} | ||
export interface InvitedToChannelUpdate extends ChannelStateUpdate { | ||
type: 'InvitedToChannel'; | ||
} | ||
export interface KickedFromChannelUpdate extends ChannelStateUpdate { | ||
type: 'KickedFromChannel'; | ||
} | ||
interface ChannelAdminUpdate extends ChannelStateUpdate { | ||
admin: Peer; | ||
} | ||
export interface ChannelAdminDeletedUpdate extends ChannelAdminUpdate { | ||
type: 'ChannelAdminDeleted'; | ||
} | ||
export interface ChannelAdminAddedUpdate extends ChannelAdminUpdate { | ||
type: 'ChannelAdminAdded'; | ||
} | ||
export interface NewChannelSubscriberUpdate extends ChannelStateUpdate { | ||
type: 'NewChannelSubscriber'; | ||
peer: Peer; | ||
} | ||
export interface ChannelPermissionsGrantedUpdate extends Update { | ||
type: 'ChannelPermissionsGranted'; | ||
channel: Peer & { | ||
name: string; | ||
}; | ||
permissions: ChannelPermission[]; | ||
} | ||
export interface ChannelPermissionsRevokedUpdate extends Update { | ||
type: 'ChannelPermissionsRevoked'; | ||
channelId: string; | ||
} | ||
export interface InlineCommandSelectedUpdate extends Update { | ||
type: 'InlineCommandSelected'; | ||
dialog: Peer; | ||
sender: Peer; | ||
metadata: string; | ||
content: string; | ||
messageId: string; | ||
} | ||
export interface MessageIdAssignedUpdate extends Update { | ||
type: 'MessageIdAssigned'; | ||
id: string; | ||
localId: string; | ||
dialog: Peer; | ||
} | ||
export interface QuickButtonSelectedUpdate extends Update { | ||
type: 'QuickButtonSelected'; | ||
dialog: Peer; | ||
sender: Peer; | ||
metadata: string; | ||
} | ||
export interface InlineCommand { | ||
/** Button caption. Max length - 32, recommended - 20 */ | ||
caption: string; | ||
/** JSON or any string to be returned in InlineCommandSelected update */ | ||
metadata: string; | ||
} | ||
export interface QuickButtonCommand { | ||
/** Button caption. Max length - 32, recommended - 20 */ | ||
caption: string; | ||
/** | ||
* JSON or any string to be returned to a service as a parameter in | ||
* update QuickButtonSelected for processing and/or data used by client | ||
* to perform specific action | ||
* | ||
* More info: https://btsdigital.github.io/bot-api-contract/quickbuttoncommand.html | ||
*/ | ||
metadata: string; | ||
action: 'QUICK_REQUEST' | 'QUICK_FORM_ACTION'; | ||
} | ||
export interface ReplyCommand { | ||
/** Button caption. Max length - 32, recommended - 20 */ | ||
caption: string; | ||
} | ||
export interface UiState { | ||
@@ -224,5 +38,13 @@ canWriteText?: boolean; | ||
showSpeechToTextButton?: boolean; | ||
/** | ||
* A list composed of QuickButtonCommand objects (or KeyboardBuilder with reply commands) | ||
*/ | ||
replyKeyboard?: ReplyCommand[] | KeyboardBuilder; | ||
/** | ||
* A list composed of QuickButtonCommand objects (or KeyboardBuilder with quick buttons) | ||
* | ||
* Max length - 25 | ||
*/ | ||
quickButtonCommands?: QuickButtonCommand[] | KeyboardBuilder; | ||
formMessage?: any; | ||
formMessage?: FormMessage | Form; | ||
} | ||
@@ -232,2 +54,1 @@ export interface ApiObject extends ApiMethods { | ||
} | ||
export {}; |
@@ -1,4 +0,6 @@ | ||
import { FileMedia } from './index'; | ||
import { Audio } from '../../interfaces'; | ||
export declare class AudioMedia extends FileMedia<Audio, 'Audio'> { | ||
import { FileMedia, BaseFileMedia } from '.'; | ||
export interface AudioPayload extends BaseFileMedia { | ||
type: 'Audio'; | ||
} | ||
export declare class AudioMedia extends FileMedia<AudioPayload, 'Audio'> { | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.AudioMedia = void 0; | ||
const index_1 = require("./index"); | ||
class AudioMedia extends index_1.FileMedia { | ||
const _1 = require("."); | ||
class AudioMedia extends _1.FileMedia { | ||
} | ||
exports.AudioMedia = AudioMedia; |
@@ -1,3 +0,22 @@ | ||
import { Media } from './index'; | ||
import { ContactMediaPayload, ContactMediaType, Avatar, User } from '../../interfaces'; | ||
import { Media, ImagePayload } from '.'; | ||
export interface RegisteredContactPayload { | ||
type: 'RegisteredContact'; | ||
user: User; | ||
} | ||
export interface UnregisteredContactPayload { | ||
type: 'UnregisteredContact'; | ||
firstName?: string; | ||
lastName?: string; | ||
phoneNumber?: string; | ||
} | ||
export interface User extends UnregisteredContactPayload { | ||
userName: string; | ||
avatar: Avatar; | ||
} | ||
export interface Avatar { | ||
full: ImagePayload; | ||
small: ImagePayload; | ||
} | ||
export declare type ContactMediaType = ContactMediaPayload['type']; | ||
export declare type ContactMediaPayload = RegisteredContactPayload | UnregisteredContactPayload; | ||
export declare class ContactMedia<P extends ContactMediaPayload, Type extends ContactMediaType = ContactMediaType> extends Media<P, Type> { | ||
@@ -4,0 +23,0 @@ get isRegistered(): boolean; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ContactMedia = void 0; | ||
const index_1 = require("./index"); | ||
class ContactMedia extends index_1.Media { | ||
const _1 = require("."); | ||
class ContactMedia extends _1.Media { | ||
get isRegistered() { | ||
@@ -7,0 +7,0 @@ return this.type === 'RegisteredContact'; |
@@ -1,4 +0,6 @@ | ||
import { FileMedia } from './index'; | ||
import { Document } from '../../interfaces'; | ||
export declare class DocumentMedia extends FileMedia<Document, 'Document'> { | ||
import { FileMedia, BaseFileMedia } from '.'; | ||
export interface DocumentPayload extends BaseFileMedia { | ||
type: 'Document'; | ||
} | ||
export declare class DocumentMedia extends FileMedia<DocumentPayload, 'Document'> { | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.DocumentMedia = void 0; | ||
const index_1 = require("./index"); | ||
class DocumentMedia extends index_1.FileMedia { | ||
const _1 = require("."); | ||
class DocumentMedia extends _1.FileMedia { | ||
} | ||
exports.DocumentMedia = DocumentMedia; |
/// <reference types="node" /> | ||
import { Media } from './index'; | ||
import { BaseFileMedia, InputMedia } from '../../interfaces'; | ||
import { Media } from '.'; | ||
export interface BaseFileMedia { | ||
type: 'Image' | 'Video' | 'Audio' | 'Document' | 'Gif' | 'Music'; | ||
fileId: string; | ||
mimeType: string; | ||
name: string; | ||
size: number; | ||
} | ||
export interface InputMedia { | ||
fileId: string; | ||
name: string; | ||
mediaType: 'IMAGE' | 'VIDEO' | 'AUDIO' | 'DOCUMENT'; | ||
} | ||
export declare class FileMedia<P extends BaseFileMedia, Type extends BaseFileMedia['type'] = BaseFileMedia['type']> extends Media<P, Type> { | ||
@@ -5,0 +16,0 @@ get fileId(): string; |
@@ -8,5 +8,5 @@ "use strict"; | ||
const node_fetch_1 = __importDefault(require("node-fetch")); | ||
const index_1 = require("./index"); | ||
const _1 = require("."); | ||
const utils_1 = require("../../utils"); | ||
class FileMedia extends index_1.Media { | ||
class FileMedia extends _1.Media { | ||
get fileId() { | ||
@@ -33,6 +33,6 @@ return this.payload.fileId; | ||
get downloadStream() { | ||
return this.download.then(res => res.body); | ||
return this.download.then(response => response.body); | ||
} | ||
get downloadBuffer() { | ||
return this.download.then(res => res.buffer()); | ||
return this.download.then(response => response.buffer()); | ||
} | ||
@@ -39,0 +39,0 @@ get isSendable() { |
@@ -1,4 +0,9 @@ | ||
import { FileMedia } from './index'; | ||
import { Gif } from '../../interfaces'; | ||
export declare class GifMedia extends FileMedia<Gif, 'Gif'> { | ||
import { FileMedia, BaseFileMedia } from '.'; | ||
export interface GifPayload extends BaseFileMedia { | ||
type: 'Gif'; | ||
width: number; | ||
height: number; | ||
duration: number; | ||
} | ||
export declare class GifMedia extends FileMedia<GifPayload, 'Gif'> { | ||
get width(): number; | ||
@@ -5,0 +10,0 @@ get height(): number; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.GifMedia = void 0; | ||
const index_1 = require("./index"); | ||
const _1 = require("."); | ||
const utils_1 = require("../../utils"); | ||
class GifMedia extends index_1.FileMedia { | ||
class GifMedia extends _1.FileMedia { | ||
get width() { | ||
@@ -8,0 +8,0 @@ return this.payload.width; |
@@ -1,4 +0,8 @@ | ||
import { FileMedia } from './index'; | ||
import { Image } from '../../interfaces'; | ||
export declare class ImageMedia extends FileMedia<Image, 'Image'> { | ||
import { FileMedia, BaseFileMedia } from '.'; | ||
export interface ImagePayload extends BaseFileMedia { | ||
type: 'Image'; | ||
width: number; | ||
height: number; | ||
} | ||
export declare class ImageMedia extends FileMedia<ImagePayload, 'Image'> { | ||
get width(): number; | ||
@@ -5,0 +9,0 @@ get height(): number; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ImageMedia = void 0; | ||
const index_1 = require("./index"); | ||
const _1 = require("."); | ||
const utils_1 = require("../../utils"); | ||
class ImageMedia extends index_1.FileMedia { | ||
class ImageMedia extends _1.FileMedia { | ||
get width() { | ||
@@ -8,0 +8,0 @@ return this.payload.width; |
import { Aitu } from '../../aitu'; | ||
import { MediaType, MediaPayload } from '../../interfaces'; | ||
import { ImagePayload, VideoPayload, DocumentPayload, AudioPayload, RegisteredContactPayload, UnregisteredContactPayload, GifPayload, MusicPayload } from '.'; | ||
export declare type MediaPayload = ImagePayload | VideoPayload | DocumentPayload | AudioPayload | RegisteredContactPayload | UnregisteredContactPayload | GifPayload | MusicPayload; | ||
export declare type MediaType = MediaPayload['type']; | ||
export declare type MediaOptions<P = {}, Type extends MediaType = MediaType> = { | ||
@@ -4,0 +6,0 @@ aitu: Aitu; |
@@ -5,3 +5,3 @@ "use strict"; | ||
const inspectable_1 = require("inspectable"); | ||
const index_1 = require("./index"); | ||
const _1 = require("."); | ||
class Media { | ||
@@ -15,10 +15,10 @@ constructor(options) { | ||
const handlers = { | ||
Image: index_1.ImageMedia, | ||
Video: index_1.VideoMedia, | ||
Document: index_1.DocumentMedia, | ||
Audio: index_1.AudioMedia, | ||
RegisteredContact: index_1.ContactMedia, | ||
UnregisteredContact: index_1.ContactMedia, | ||
Gif: index_1.GifMedia, | ||
Music: index_1.MusicMedia | ||
Image: _1.ImageMedia, | ||
Video: _1.VideoMedia, | ||
Document: _1.DocumentMedia, | ||
Audio: _1.AudioMedia, | ||
RegisteredContact: _1.ContactMedia, | ||
UnregisteredContact: _1.ContactMedia, | ||
Gif: _1.GifMedia, | ||
Music: _1.MusicMedia | ||
}; | ||
@@ -25,0 +25,0 @@ const MediaConstructor = handlers[media.type]; |
@@ -1,6 +0,9 @@ | ||
import { FileMedia } from './index'; | ||
import { Music } from '../../interfaces'; | ||
export declare class MusicMedia extends FileMedia<Music, 'Music'> { | ||
import { FileMedia, BaseFileMedia } from '.'; | ||
export interface MusicPayload extends BaseFileMedia { | ||
type: 'Music'; | ||
duration: number; | ||
} | ||
export declare class MusicMedia extends FileMedia<MusicPayload, 'Music'> { | ||
get duration(): number; | ||
serialize(): Record<string, unknown>; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.MusicMedia = void 0; | ||
const index_1 = require("./index"); | ||
const _1 = require("."); | ||
const utils_1 = require("../../utils"); | ||
class MusicMedia extends index_1.FileMedia { | ||
class MusicMedia extends _1.FileMedia { | ||
get duration() { | ||
@@ -8,0 +8,0 @@ return this.payload.duration; |
@@ -1,4 +0,9 @@ | ||
import { FileMedia } from './index'; | ||
import { Video } from '../../interfaces'; | ||
export declare class VideoMedia extends FileMedia<Video, 'Video'> { | ||
import { FileMedia, BaseFileMedia } from '.'; | ||
export interface VideoPayload extends BaseFileMedia { | ||
type: 'Video'; | ||
width: number; | ||
height: number; | ||
duration: number; | ||
} | ||
export declare class VideoMedia extends FileMedia<VideoPayload, 'Video'> { | ||
get width(): number; | ||
@@ -5,0 +10,0 @@ get height(): number; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.VideoMedia = void 0; | ||
const index_1 = require("./index"); | ||
const _1 = require("."); | ||
const utils_1 = require("../../utils"); | ||
class VideoMedia extends index_1.FileMedia { | ||
class VideoMedia extends _1.FileMedia { | ||
get width() { | ||
@@ -8,0 +8,0 @@ return this.payload.width; |
export * from './keyboard-builder'; | ||
export * from './keyboard'; | ||
export * from './form'; | ||
export * from './container'; | ||
export * from './header'; | ||
export * from './options'; | ||
export * from './indent'; | ||
export * from './form-action'; | ||
export * from './flex-options'; | ||
export * from './validation-rule'; | ||
export * from './file-metadata'; | ||
export * from './content'; |
@@ -13,3 +13,17 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
// Keyboards | ||
__exportStar(require("./keyboard-builder"), exports); | ||
__exportStar(require("./keyboard"), exports); | ||
// Helper classes | ||
__exportStar(require("./form"), exports); | ||
__exportStar(require("./container"), exports); | ||
// Common interfaces | ||
__exportStar(require("./header"), exports); | ||
__exportStar(require("./options"), exports); | ||
__exportStar(require("./indent"), exports); | ||
__exportStar(require("./form-action"), exports); | ||
__exportStar(require("./flex-options"), exports); | ||
__exportStar(require("./validation-rule"), exports); | ||
__exportStar(require("./file-metadata"), exports); | ||
// Content interfaces | ||
__exportStar(require("./content"), exports); |
@@ -1,2 +0,2 @@ | ||
import { InlineCommand, QuickButtonCommand, ReplyCommand } from '../../interfaces'; | ||
import { InlineCommand, QuickButtonCommand, ReplyCommand, QuickButtonCommandInput } from '.'; | ||
export declare type KeyboardRow = (InlineCommand | QuickButtonCommand | ReplyCommand)[]; | ||
@@ -9,3 +9,3 @@ export declare class KeyboardBuilder { | ||
inlineCommand(options: InlineCommand): this; | ||
quickButtonCommand(options: QuickButtonCommand): this; | ||
quickButtonCommand(options: QuickButtonCommandInput): this; | ||
replyCommand(options: ReplyCommand): this; | ||
@@ -12,0 +12,0 @@ private ensureType; |
@@ -28,2 +28,5 @@ "use strict"; | ||
} | ||
if (typeof options.metadata !== 'string') { | ||
options.metadata = JSON.stringify(options.metadata); | ||
} | ||
this.currentRow.push(options); | ||
@@ -30,0 +33,0 @@ return this; |
@@ -1,4 +0,3 @@ | ||
import { KeyboardBuilder } from './index'; | ||
import { KeyboardBuilder, FormAction } from '.'; | ||
import { AllowArray } from '../../types'; | ||
import { InlineCommand, QuickButtonCommand, ReplyCommand } from '../../interfaces'; | ||
export interface ProxyButton { | ||
@@ -8,2 +7,38 @@ kind: 'inlineCommand' | 'quickButtonCommand' | 'replyCommand'; | ||
} | ||
export interface InlineCommand { | ||
/** Button caption. Max length - 32, recommended - 20 */ | ||
caption: string; | ||
/** JSON or any string to be returned in InlineCommandSelected update */ | ||
metadata: string; | ||
} | ||
export interface QuickButtonCommand { | ||
/** Button caption. Max length - 32, recommended - 20 */ | ||
caption: string; | ||
/** | ||
* JSON or any string to be returned to a service as a parameter in | ||
* update QuickButtonSelected for processing and/or data used by client | ||
* to perform specific action | ||
* | ||
* More info: https://btsdigital.github.io/bot-api-contract/quickbuttoncommand.html | ||
*/ | ||
metadata: string; | ||
action: 'QUICK_REQUEST' | 'QUICK_FORM_ACTION'; | ||
} | ||
export interface QuickButtonCommandInput { | ||
/** Button caption. Max length - 32, recommended - 20 */ | ||
caption: string; | ||
/** | ||
* JSON or any string to be returned to a service as a parameter in | ||
* update QuickButtonSelected for processing and/or data used by client | ||
* to perform specific action | ||
* | ||
* More info: https://btsdigital.github.io/bot-api-contract/quickbuttoncommand.html | ||
*/ | ||
metadata: string | FormAction; | ||
action: 'QUICK_REQUEST' | 'QUICK_FORM_ACTION'; | ||
} | ||
export interface ReplyCommand { | ||
/** Button caption. Max length - 32, recommended - 20 */ | ||
caption: string; | ||
} | ||
export declare class Keyboard { | ||
@@ -13,4 +48,4 @@ static builder(): KeyboardBuilder; | ||
static inlineCommand(options: InlineCommand): ProxyButton; | ||
static quickButtonCommand(options: QuickButtonCommand): ProxyButton; | ||
static quickButtonCommand(options: QuickButtonCommandInput): ProxyButton; | ||
static replyCommand(options: ReplyCommand): ProxyButton; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Keyboard = void 0; | ||
const index_1 = require("./index"); | ||
const _1 = require("."); | ||
class Keyboard { | ||
static builder() { | ||
return new index_1.KeyboardBuilder(); | ||
return new _1.KeyboardBuilder(); | ||
} | ||
static keyboard(rows) { | ||
const builder = new index_1.KeyboardBuilder(); | ||
const builder = new _1.KeyboardBuilder(); | ||
for (const row of rows) { | ||
@@ -25,2 +25,5 @@ const buttons = Array.isArray(row) ? row : [row]; | ||
static quickButtonCommand(options) { | ||
if (typeof options.metadata !== 'string') { | ||
options.metadata = JSON.stringify(options.metadata); | ||
} | ||
return { options, kind: 'quickButtonCommand' }; | ||
@@ -27,0 +30,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import { Middleware } from 'middleware-io'; | ||
import { Middleware, Composer, MiddlewareReturn } from 'middleware-io'; | ||
import { Aitu } from './aitu'; | ||
@@ -10,3 +10,3 @@ import { AllowArray } from './types'; | ||
private retries; | ||
private composer; | ||
composer: Composer<Context<{}, string>, Context<{}, string>>; | ||
private composed; | ||
@@ -29,4 +29,4 @@ constructor(aitu: Aitu); | ||
private handleUpdate; | ||
dispatchMiddleware(context: Context): unknown; | ||
dispatchMiddleware(context: Context): MiddlewareReturn; | ||
protected recompose(): void; | ||
} |
@@ -109,5 +109,5 @@ "use strict"; | ||
} | ||
catch (e) { | ||
catch (error) { | ||
this.isStarted = false; | ||
throw e; | ||
throw error; | ||
} | ||
@@ -120,6 +120,6 @@ } | ||
} | ||
catch (e) { | ||
debug('startFetchLoop:', e); | ||
catch (error) { | ||
debug('startFetchLoop:', error); | ||
if (this.retries === this.aitu.options.pollingRetryLimit) { | ||
throw e; | ||
throw error; | ||
} | ||
@@ -146,5 +146,5 @@ this.retries = this.retries + 1; | ||
} | ||
catch (e) { | ||
catch (error) { | ||
debug('JSON parsing error', responseJson); | ||
throw e; | ||
throw error; | ||
} | ||
@@ -157,3 +157,4 @@ // debug('updateResponse', updateResponse) | ||
const { updates } = updateResponse; | ||
if (!updates.length) | ||
this.retries = 0; | ||
if (updates.length === 0) | ||
return; | ||
@@ -187,3 +188,2 @@ updates.forEach((update) => this.handleUpdate(update)); | ||
inspectable_1.inspectable(Updates, { | ||
// @ts-expect-error | ||
serialize: ({ isStarted, composer }) => ({ | ||
@@ -190,0 +190,0 @@ isStarted, |
{ | ||
"name": "aitu", | ||
"version": "1.0.0-alpha.0", | ||
"version": "1.0.0-alpha.1", | ||
"description": "Package for Aitu services API (unofficial)", | ||
@@ -47,2 +47,3 @@ "author": { | ||
"eslint-plugin-standard": "^4.0.1", | ||
"eslint-plugin-unicorn": "^21.0.0", | ||
"ts-node": "^9.0.0", | ||
@@ -49,0 +50,0 @@ "typescript": "^4.0.2" |
@@ -26,3 +26,3 @@ # aitu | ||
- [x] getChannelInfo | ||
- [ ] getChannelMessages - UNKNOWN REQUIRED `direction` PARAMETER | ||
- [ ] getChannelMessages (direction = EARLY | LATER | AROUND, messageId - required if direction is AROUND) | ||
- [ ] uploadFiles | ||
@@ -33,3 +33,3 @@ - [x] downloadFile - Supported in FileMedia | ||
- [x] getChannelAdmins | ||
- [ ] getAvatar - Probably won't be supported | ||
- [ ] getAvatar | ||
- [x] getWebhookInfo | ||
@@ -39,3 +39,3 @@ - [x] setWebhook | ||
- [ ] Files uploader | ||
- [ ] Form builder | ||
- [x] Form builder | ||
- [x] QuickButton keyboard builder | ||
@@ -47,2 +47,3 @@ - [x] InlineCommand keyboard builder | ||
- [ ] Write documentation | ||
- [ ] Add more examples | ||
- [x] `context.state` | ||
@@ -54,4 +55,6 @@ - [ ] Proper handlers like `hear(conditions, handler)` that supports RegEx, Strings, Functions as conditions | ||
- [x] Consider renaming `Aitu.callApi` to `api` | ||
- [ ] Add CI | ||
- [x] Add CI | ||
- [ ] Serialize/parse button metatada (if it's an object) | ||
- [ ] Add types for QuickButtonCommand actions? | ||
- [x] Add types for QuickButtonCommand actions | ||
- [ ] Split content options into separate interfaces | ||
- [ ] Add catalog content type |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
100667
170
2792
56
16
2