///
import { EventEmitter } from 'node:events';
import { ReadableStream as ReadableStream_2 } from 'node:stream/web';
declare namespace API {
export {
Downloader_2 as Downloader,
DownloadCode,
Uploader_2 as Uploader,
MediaType,
UploadResult,
Card,
Instances
}
}
export declare const APIConnectionError: typeof Errors.APIConnectionError;
declare class APIConnectionError_2 extends APIError_2 {
readonly status: undefined;
constructor({ message, cause, }: {
message?: string;
cause?: Error | undefined;
});
}
export declare const APIConnectionTimeoutError: typeof Errors.APIConnectionTimeoutError;
declare class APIConnectionTimeoutError_2 extends APIConnectionError_2 {
constructor({ message }?: {
message?: string;
});
}
export declare const APIError: typeof Errors.APIError;
declare class APIError_2 extends DingtalkError_2 {
readonly status: number | undefined;
readonly headers: Headers | undefined;
readonly error: NonNullable | undefined;
readonly code: string | null | undefined;
constructor(status: number | undefined, error: NonNullable | undefined, message: string | undefined, headers: Headers | undefined);
private static makeMessage;
static generate(status: number | undefined, errorResponse: NonNullable | undefined, message?: string | undefined, headers?: Headers | undefined): APIError_2;
}
declare class APIResource {
protected client: DingtalkClient;
protected post: DingtalkClient['post'];
constructor(client: DingtalkClient);
}
export declare const APIUserAbortError: typeof Errors.APIUserAbortError;
declare class APIUserAbortError_2 extends APIError_2 {
readonly status: undefined;
constructor({ message }?: {
message?: string;
});
}
export declare const AuthenticationError: typeof Errors.AuthenticationError;
declare class AuthenticationError_2 extends APIError_2 {
readonly status = 401;
}
export declare const BadRequestError: typeof Errors.BadRequestError;
declare class BadRequestError_2 extends APIError_2 {
readonly status = 400;
}
declare class Card extends APIResource {
instances: InstancesAPI.Instances;
}
declare type CardData = {
cardParamMap?: CardParamMap & {
sys_full_json_obj?: string;
};
};
declare type CardInstanceError = {
code: string;
requestId: string;
message: string;
};
declare type CardInstanceResponse = {
success: boolean;
result: T;
};
/**
* 创建互动卡片实例
*
* @see https://open.dingtalk.com/document/orgapp/interface-for-creating-a-card-instance
*/
declare interface CardInstancesCreateParams {
/**
* 卡片创建者的用户 ID
*/
userId?: string;
/**
* 用户 ID 类型
*
* 1 userId
* 2 unionId
*/
userIdType?: number;
/**
* 卡片内容模板ID
*
* @see https://open-dev.dingtalk.com/fe/card
*/
cardTemplateId: string;
/**
* 外部卡片实例Id
*/
outTrackId: string;
/**
* 卡片回调的类型
*
* - STREAM
* - HTTP
*
* 注意参数均为大写
*/
callbackType?: 'STREAM' | 'HTTP';
/**
* 卡片回调HTTP模式时的路由 Key,用于查询注册的 callbackUrl
*/
callbackRouteKey?: string;
/**
* 卡片数据
*/
cardData: CardData;
/**
* 私有数据
*
* key 是用户 ID
*/
privateData?: Record;
/**
* 动态数据源配置
*/
openDynamicDataConfig?: {
/**
* 动态数据源配置列表
*/
dynamicDataSourceConfigs?: OpenDynamicDataConfig.SourceConfig[];
};
/**
* IM 群聊场域信息
*/
imGroupOpenSpaceModel?: OpenSpaceModel;
/**
* IM 单聊场域信息
*/
imRobotOpenSpaceModel?: OpenSpaceModel;
/**
* 协作场域信息
*/
coFeedOpenSpaceModel?: {
/**
* 卡片标题
*/
title?: string;
/**
* 吊顶场域属性,通过增加spaeType使卡片支持吊顶场域
*/
topOpenSpaceModel?: {
spaceType: string;
};
};
}
declare type CardInstancesDeliverParams = {
/**
* 外部卡片实例 ID
*/
outTrackId: string;
/**
* 卡片投放的场域
*/
openSpaceId: string;
/**
* IM机器人单聊投放参数
*/
imRobotOpenDeliverModel?: {
robotCode?: string;
spaceType?: string;
extension?: Record;
};
/**
* 群聊投放参数
*/
imGroupOpenDeliverModel?: {
robotCode?: string;
atUserIds: Record;
recipients?: string[];
extension?: Record;
};
/**
* 吊顶投放参数
*/
topOpenDeliverModel?: {
expiredTimeMillis?: string;
userIds?: string[];
platforms: string[];
};
/**
* 协作投放参数
*/
coFeedOpenDeliverModel?: {
/**
* 业务标识
*/
bizTag?: string;
/**
* 协作场域下的排序时间
*/
gmtTimeLine: string;
};
/**
* 文档投放参数
*/
docOpenDeliverModel?: {
userId?: string;
};
userIdType?: number;
};
/**
* 发送互动卡片
*
* @see https://open.dingtalk.com/document/orgapp-server/send-dingtalk-interactive-cards
*/
declare type CardInstancesSendParams = {
/**
* 互动卡片的消息模板ID
*/
cardTemplateId: string;
/**
* 唯一标示卡片的外部编码
*/
outTrackId: string;
/**
* 机器人唯一编码
*/
robotCode?: string;
/**
* 机器人ID
*/
chatBotId?: string;
/**
* 群ID
*/
openConversationId: string;
/**
* 会话类型
*
* - 0 单聊
* - 1 群聊
*
* @remarks 和消息的会话类型不同
*/
conversationType: number;
/**
* 接收用户列表
*/
receiverUserIdList: string[];
/**
* 消息提及的人
*/
atOpenIds?: Record;
/**
* 用户ID类型
*/
userIdType?: number;
/**
* 卡片回调时的路由Key,用于查询注册的callbackUrl
*/
callbackRouteKey?: string;
/**
* 卡片数据
*/
cardData: CardData;
/**
* 卡片选项
*/
cardOptions?: {
supportForward: boolean;
};
/**
* 私有数据
*/
privateData?: Record;
/**
* 拉取策略
*
* - true:开启卡片纯拉模式
* - false:不开启卡片纯拉模式
*/
pullStrategy?: boolean;
};
/**
* 卡片模板内容替换参数
*/
declare type CardParamMap = Record;
/**
* 配置
*/
declare type Configuration = {
/**
* 应用的唯一标识
*/
clientId?: string | undefined;
/**
* 应用的密钥
*/
clientSecret?: string | undefined;
[key: string]: any;
};
export declare const ConflictError: typeof Errors.ConflictError;
declare class ConflictError_2 extends APIError_2 {
readonly status = 409;
}
declare type Conversation = ConversationProperties & TalkerProperties & RobotProperties & Incoming.Message;
/**
* 会话消息
*/
declare interface ConversationProperties {
/**
* 会话ID
*/
conversationId: string;
/**
* 会话类型
*
* - 1: 私聊
* - 2: 群聊
*/
conversationType: '2' | '1';
/**
* 会话标题
*
* 只有在群聊中才有
*/
conversationTitle?: string;
/**
* 消息ID
*/
msgId: string;
/**
* 引用消息ID
*/
originalMsgId?: string;
/**
* 引用消息查询 Key
*/
originalProcessQueryKey?: string;
/**
* 消息创建时间
*/
createAt: number;
/**
* 是否在被提及列表中
*/
isInAtList?: boolean;
/**
* 被提及的用户
*/
atUsers?: Array<{
staffId: string;
}>;
}
export declare type Credentials = {
clientId: string;
clientSecret: string;
};
export declare const CustomizeWebhook: typeof Robots.CustomizeWebhook;
/**
* 自定义机器人接入
*
* @see https://open.dingtalk.com/document/isvapp/custom-bot-access-send-message
*/
declare class CustomizeWebhook_2 {
token: string;
secret?: string;
apiBaseUrl: string;
endpoint: string;
constructor(settings: CustomizeWebhookSettings);
say(sayable: string | Outgoing.Message): Promise;
send(message: Outgoing.Message): Promise;
protected buildURL(): string;
}
declare type CustomizeWebhookSettings = {
/**
* 钉钉开放平台网关地址
*
* @defaultValue https://oapi.dingtalk.com
*/
apiBaseUrl?: string;
/**
* 机器人接口地址
*/
endpoint?: string;
/**
* 授权令牌
*/
token: string;
/**
* 加密密钥
*
* see https://open.dingtalk.com/document/robots/customize-robot-security-settings
*/
secret?: string;
};
declare class DingtalkClient {
clientId: string;
clientSecret: string;
baseUrl: string;
config: Configuration;
constructor(options?: Configuration);
session: SessionCredentials;
uploader: API.Uploader;
downloader: API.Downloader;
card: API.Card;
post(url: string, body?: BodyInit, options?: Omit): Promise;
/**
* 获取临时授权码
*
* @returns 临时授权码
*/
getAccessToken(): Promise;
/**
* 授权请求头
*
* @returns 授权请求头
*/
authHeaders(): Promise>;
/**
* 默认请求头
*
* @returns 默认请求头
*/
defaultHeaders(): Promise>;
static config: Configuration;
static SubscriptionType: typeof EventBus.SubscriptionType;
static Subscriptions: {
readonly AllEvent: EventBus.SubscriptionItem;
readonly ImMessage: EventBus.SubscriptionItem;
};
static SessionWebhook: typeof Robots.SessionWebhook;
static CustomizeWebhook: typeof Robots.CustomizeWebhook;
static IncomingType: typeof Robots.Incoming.ContentType;
static OutgoingType: typeof Robots.Outgoing.ContentType;
}
declare namespace DingtalkClient {
type MediaType = API.MediaType;
type Uploader = API.Uploader;
type UploadResult = API.UploadResult;
type Downloader = API.Downloader;
type SubscriptionType = EventBus.SubscriptionType;
type SubscriptionItem = EventBus.SubscriptionItem;
type IncomingMessage = Robots.IncomingMessage;
type RichTextSectionImage = Robots.Incoming.RichText.ImageSection;
}
export { DingtalkClient }
export default DingtalkClient;
export declare const DingtalkError: typeof Errors.DingtalkError;
declare class DingtalkError_2 extends Error {
}
/**
* 临时下载码
*
* @see https://open.dingtalk.com/document/orgapp/download-the-file-content-of-the-robot-receiving-message
*/
declare type DownloadCode = string;
export declare const Downloader: typeof API.Downloader;
declare class Downloader_2 extends APIResource {
endpoint: string;
/**
* 使用下载码交换文件地址
*
* @param downloadCode - 下载码
* @param robotCode - 机器人Code
*/
exchangeCode(downloadCode: DownloadCode, robotCode?: string): Promise;
/**
* 下载文件到指定位置
*
* @param url - 下载地址
* @param filePath - 文件路径
* @returns 文件路径
*/
downloadToPath(url: string, filePath: string): Promise;
/**
* 下载文件到临时目录
*
* @param url - 下载地址
* @param filename - 文件名
* @returns 临时文件路径
*/
downloadToTmp(url: string, name?: string): Promise;
protected fetchStream(url: string): Promise;
/**
* 保存数据流到文件
*
* @param stream - 数据流
* @param filePath - 绝对路径
* @returns 文件路径
*/
protected saveTo(stream: ReadableStream_2, filePath: string): Promise;
}
declare namespace Errors {
export {
DingtalkError_2 as DingtalkError,
InvalidArgumentError_2 as InvalidArgumentError,
InvalidResultError,
APIError_2 as APIError,
APIUserAbortError_2 as APIUserAbortError,
APIConnectionError_2 as APIConnectionError,
APIConnectionTimeoutError_2 as APIConnectionTimeoutError,
BadRequestError_2 as BadRequestError,
AuthenticationError_2 as AuthenticationError,
PermissionDeniedError_2 as PermissionDeniedError,
NotFoundError_2 as NotFoundError,
ConflictError_2 as ConflictError,
UnprocessableEntityError_2 as UnprocessableEntityError,
InternalServerError_2 as InternalServerError
}
}
declare namespace EventBus {
export {
StreamClientOptions,
StreamClient_2 as StreamClient,
GraphAPIResponse,
SubscriptionType_2 as SubscriptionType,
SubscriptionItem,
SubscriptionData,
Subscriptions,
SubscriptionManager
}
}
declare interface GraphAPIResponse {
response: {
statusLine: {
code?: number;
reasonPhrase?: string;
};
headers: {
[key: string]: string;
};
body: string;
};
}
declare namespace I18n {
enum Language {
/**
* 简体中文
*/
ZH_CN = "ZH_CN",
/**
* 繁体中文
*/
ZH_TW = "ZH_TW",
/**
* 英文
*/
EN_US = "EN_US",
/**
* 日语
*/
JA_JP = "JA_JP",
/**
* 越南语
*/
VI_VN = "VI_VN"
}
}
declare namespace Incoming {
/**
* 机器人发送的消息类型
*/
enum ContentType {
Text = "text",
Audio = "audio",
Video = "video",
Image = "picture",
RichText = "richText",
File = "file"
}
namespace RichText {
type TextSection = {
text: string;
};
type ImageSection = {
type: 'picture';
downloadCode: string;
pictureDownloadCode: string;
};
type Section = TextSection | ImageSection;
}
type RichTextSection = RichText.Section;
type RichTextMessage = {
msgtype: 'richText';
content: {
richText: RichTextSection[];
};
};
type ImageMessage = {
msgtype: 'picture';
content: {
downloadCode: string;
pictureDownloadCode: string;
};
};
type AudioMessage = {
msgtype: 'audio';
content: {
duration: number;
downloadCode: string;
recognition: string;
};
};
type VideoMessage = {
msgtype: 'video';
content: {
duration: number;
downloadCode: string;
videoType: string;
};
};
type FileMessage = {
msgtype: 'file';
content: {
spaceId: string;
field: string;
downloadCode: string;
fileName: string;
};
};
type MessageMap = {
[ContentType.Text]: Outgoing.TextMessage;
[ContentType.RichText]: RichTextMessage;
[ContentType.Image]: ImageMessage;
[ContentType.Audio]: AudioMessage;
[ContentType.Video]: VideoMessage;
[ContentType.File]: FileMessage;
};
type Message = MessageMap[ContentType];
{};
}
declare class IncomingMessage {
protected client: DingtalkClient;
properties: Conversation;
Type: typeof Incoming.ContentType;
conversationId: string;
conversationType: '2' | '1';
id: string;
type: Incoming.ContentType;
text: string;
age: number;
createAt: number;
room?: Room | undefined;
robot: Robot;
talker: Talker;
webhook: SessionWebhook_2;
constructor(client: DingtalkClient, properties: Conversation);
/**
* 获取富文本内容
*
* @returns 富文本节点
*/
richText(): Incoming.RichTextSection[] | void;
/**
* 直接回复消息给发送者
*
* @param sayable - 消息内容
* @returns
*/
reply(sayable: Sayable): Promise;
/**
* 可以发送给任何消息给有权限的人
*
* @param sayable - 消息内容
*/
say(sayable: Sayable): Promise;
say(sayable: Sayable, atAll: true): Promise;
say(sayable: Sayable, mentionList: string[]): Promise;
unstable__getFileURL(): Promise;
/**
* 保存文件到临时目录中
*
* @param filename - 临时文件名
* @returns 文件路径
*/
unstable__saveFileToTmpdir(filename?: string): Promise;
/**
* 获取消息包含的文件名称
*
* @returns 文件名称
*/
unstable__filenameSync(): string | void;
}
/**
* 互动卡片
*/
declare class Instances extends APIResource {
/**
* 创建卡片
*
* @param params -
* @returns
*/
create(params: CardInstancesCreateParams): Promise;
/**
* 投放卡片
*
* @param params -
*/
deliver(params: CardInstancesDeliverParams): Promise;
/**
* 发送卡片
*
* @param params -
* @returns
*/
send(params: CardInstancesSendParams): Promise<{
processQueryKey: string;
}>;
protected afterResponse(resultInit: MaybePromise | CardInstanceError>): Promise;
}
declare namespace InstancesAPI {
export {
MaybePromise,
Instances,
CardInstancesCreateParams,
CardParamMap,
CardData,
OpenDynamicDataConfig,
OpenSpaceModel,
I18n,
CardInstanceResponse,
CardInstanceError,
CardInstancesDeliverParams,
CardInstancesSendParams
}
}
export declare const InternalServerError: typeof Errors.InternalServerError;
declare class InternalServerError_2 extends APIError_2 {
}
export declare const InvalidArgumentError: typeof Errors.InvalidArgumentError;
declare class InvalidArgumentError_2 extends DingtalkError_2 {
}
declare class InvalidResultError extends DingtalkError_2 {
}
declare type MaybePromise = T | Promise;
/**
* 媒体文件类型
*
* - image:图片,图片最大20MB。支持上传jpg、gif、png、bmp格式。
* - voice:语音,语音文件最大2MB。支持上传amr、mp3、wav格式。
* - video:视频,视频最大20MB。支持上传mp4格式。
* - file:普通文件,最大20MB。支持上传doc、docx、xls、xlsx、ppt、pptx、zip、pdf、rar格式。
*/
declare type MediaType = 'image' | 'voice' | 'file';
export declare const NotFoundError: typeof Errors.NotFoundError;
declare class NotFoundError_2 extends APIError_2 {
readonly status = 404;
}
declare namespace OpenDynamicDataConfig {
enum PullStrategy {
/**
* 不拉取,无动态数据
*/
None = "NONE",
/**
* 间隔拉取
*/
Interval = "INTERVAL",
/**
* 拉取一次
*/
Once = "ONCE"
}
enum TimeUnit {
Seconds = "SECONDS",
Minutes = "MINUTES",
Hours = "HOURS",
Days = "DAYS"
}
type SourceConfig = {
/**
* 数据源的唯一 ID, 调用方指定
*/
dynamicDataSourceId?: string;
/**
* 回调数据源时回传的固定参数
*/
constParams?: Record;
/**
* 数据源拉取配置
*/
pullConfig?: {
/**
* 拉取策略
*/
pullStrategy?: PullStrategy;
/**
* 拉取的间隔时间
*
* - 只在将pullStrategy设置为INTERVAL的时候生效。
* - 最小拉取间隔时间3s。
*/
interval?: number;
/**
* 拉取的间隔时间的单位
*/
timeUnit?: TimeUnit;
};
};
}
declare type OpenSpaceModel = {
/**
* 是否支持转发
*/
supportForward: boolean;
/**
* 支持国际化的LastMessage,目前支持的语言枚举值:
*
* ZH_CN:简体中文
* ZH_TW:繁体中文:
* EN_US:英文
* JA_JP:日语
* VI_VN:越南语
*/
lastMessageI18n?: Map;
/**
* 支持卡片消息可被搜索字段
*/
searchSupport?: {
/**
* 类型的icon,供搜索展示使用。
*/
searchIcon?: string;
/**
* 卡片类型名
*/
searchTypeName?: string;
/**
* 供消息展示与搜索的字段
*/
searchDesc?: string;
};
/**
* 通知信息
*/
notification?: {
/**
* 通知内容
*
* @defaultValue 如你收到 1 条新消息
*/
alertContent?: string;
/**
* 是否关闭推送通知
*/
notificationOff?: boolean;
};
};
declare namespace Outgoing {
/**
* 空消息
*
* 当不想回复消息到群里时,可以使用空消息
*/
type EmptyMessage = {
msgtype: 'empty';
};
/**
* 文本消息
*/
type TextMessage = WithAt<{
msgtype: 'text';
text: {
content: string;
};
}>;
/**
* Markdown 消息
*/
type MarkdownMessage = WithAt<{
msgtype: 'markdown';
markdown: {
title: string;
text: string;
};
}>;
/**
* 链接消息
*/
type LinkMessage = {
msgtype: 'link';
link: {
text: string;
title: string;
picUrl: string;
messageUrl: string;
};
};
/**
* webhook 方式不支持
*/
type ImageMessage = {
msgtype: 'picture';
image: {
photoURL: string;
};
};
type AudioMessage = {
msgtype: 'audio';
audio: {
mediaId: string;
duration: number;
};
};
type VideoMessage = {
msgtype: 'video';
video: {
/**
* 视频封面图片媒体文件ID
*
* 通过上传媒体文件接口得到的 mediaId
*/
picMediaId: string;
/**
* 视频媒体文件ID
*
* 通过上传媒体文件接口得到的 mediaId
*/
videoMediaId: string;
/**
* 视频类型,支持mp4格式。
*/
videoType: number;
/**
* 视频时长,单位:秒
*/
duration: string;
/**
* 视频展示宽度,单位px
*/
width?: string;
/**
* 视频展示高度,单位px
*/
height?: string;
};
};
type FileMessage = {
msgtype: 'file';
file: {
mediaId: string;
fileName: string;
fileType: string;
};
};
type SingleButtonActionCard = {
/**
* 首屏会话透出的展示内容
*/
title: string;
/**
* markdown 格式的消息
*/
text: string;
/**
* 单个按钮的标题
*/
singleTitle: string;
/**
* 点击 singleTitle 按钮触发的URL
*/
singleURL: string;
};
enum ActionCardButtonOrientation {
Vertical = "0",
Horizontal = "1"
}
type ActionCardButtonStyle = {
/**
* 按钮标题
*/
title: string;
/**
* 点击按钮触发的URL
*/
actionURL: string;
};
type MultiButtonActionCard = {
/**
* 首屏会话透出的展示内容
*/
title: string;
/**
* markdown 格式的消息
*/
text: string;
/**
* 按钮排列顺序
*
* 0: 按钮竖直排列
* 1: 按钮横向排列
*/
btnOrientation: ActionCardButtonOrientation;
/**
* 按钮列表
*/
btns: ActionCardButtonStyle[];
};
/**
* ActionCard 消息
*/
type ActionCardMessage = {
msgtype: 'actionCard';
actionCard: SingleButtonActionCard | MultiButtonActionCard;
};
type FeedLink = {
title: string;
messageURL: string;
picURL: string;
};
/**
* FeedCard 消息
*
* 接口方式不支持
*/
type FeedCardMessage = {
msgtype: 'feedCard';
feedCard: {
links: FeedLink[];
};
};
/**
* 机器人发送的消息类型
*/
enum ContentType {
Empty = "empty",
Text = "text",
Markdown = "markdown",
Link = "link",
Image = "image",
Audio = "audio",
Video = "video",
File = "file",
ActionCard = "actionCard",
FeedCard = "feedCard"
}
type At = {
atUserIds?: string[];
atMobiles?: string[];
isAtAll?: boolean;
};
type WithAt = T & {
at?: At;
};
type MessageMap = {
[ContentType.Empty]: EmptyMessage;
[ContentType.Text]: TextMessage;
[ContentType.Markdown]: MarkdownMessage;
[ContentType.Link]: LinkMessage;
[ContentType.Image]: ImageMessage;
[ContentType.Audio]: AudioMessage;
[ContentType.Video]: VideoMessage;
[ContentType.File]: FileMessage;
[ContentType.ActionCard]: ActionCardMessage;
[ContentType.FeedCard]: FeedCardMessage;
};
/**
* 机器人发送的消息类型
*
* https://open.dingtalk.com/document/orgapp/robot-message-types-and-data-format
*/
type Message = MessageMap[ContentType];
{};
}
export declare const PermissionDeniedError: typeof Errors.PermissionDeniedError;
declare class PermissionDeniedError_2 extends APIError_2 {
readonly status = 403;
}
export declare type RichTextSectionImage = Robots.Incoming.RichText.ImageSection;
declare class Robot extends SayableSayer {
incoming: IncomingMessage;
id: string;
code: string;
corpId: string;
webhook: SessionWebhook_2;
constructor(incoming: IncomingMessage, // TODO 暂定,用于调用其他 API
{ chatbotUserId, robotCode, chatbotCorpId, sessionWebhook, sessionWebhookExpiredTime, }: RobotProperties);
protected send(message: Outgoing.Message): Promise;
}
declare interface RobotProperties {
/**
* 机器人ID
*/
chatbotUserId: string;
/**
* 机器人Code
*/
robotCode: string;
/**
* 企业ID
*/
chatbotCorpId: string;
/**
* 当前会话的 Webhook 地址
*/
sessionWebhook: string;
/**
* 当前会话的 Webhook 地址过期时间
*/
sessionWebhookExpiredTime: number;
}
declare namespace Robots {
export {
Incoming,
Outgoing,
ConversationProperties,
Conversation,
RobotProperties,
TalkerProperties,
CustomizeWebhookSettings,
CustomizeWebhook_2 as CustomizeWebhook,
SessionWebhookSettings,
SessionWebhook_2 as SessionWebhook,
IncomingMessage,
Sayable,
SayableSayer
}
}
declare class Room {
protected incoming: IncomingMessage;
id: string;
name: string;
constructor(incoming: IncomingMessage, properties: ConversationProperties);
say(sayable: Sayable): Promise;
say(sayable: Sayable, atAll: true): Promise;
say(sayable: Sayable, mentionList: string[]): Promise;
reply(sayable: Sayable): Promise;
}
declare type Sayable = string | Outgoing.Message;
declare abstract class SayableSayer {
say(sayable: Sayable): Promise;
say(sayable: Sayable, atAll: true): Promise;
say(sayable: Sayable, mentionList: string[]): Promise;
protected abstract send(message: Outgoing.Message): Promise;
protected mention(message: Outgoing.Message): Outgoing.Message;
protected mention(message: Outgoing.Message, atAll: true): Outgoing.Message;
protected mention(message: Outgoing.Message, mentionList: string[]): Outgoing.Message;
protected atAll(message: Outgoing.Message): Outgoing.Message;
protected atUserIds(message: Outgoing.Message, userIds: string[]): Outgoing.Message;
protected resolve(sayable: Sayable): Promise;
}
/**
* 获取企业内部应用的身份凭证
*
* @see https://open.dingtalk.com/document/orgapp/obtain-the-access_token-of-an-internal-app
*/
export declare class SessionCredentials {
#private;
protected credentials: Credentials;
constructor(credentials: Credentials);
getAccessToken(): Promise;
protected process(): Promise;
protected request(): Promise;
}
export declare const SessionWebhook: typeof Robots.SessionWebhook;
/**
* see https://open.dingtalk.com/document/orgapp/receive-message
*/
declare class SessionWebhook_2 {
sessionWebhook: string;
sessionWebhookExpiredTime: number;
constructor(settings: SessionWebhookSettings);
is_expired(): boolean;
send(message: Outgoing.Message): Promise;
}
declare type SessionWebhookSettings = {
/**
* 当前会话的 Webhook 地址
*/
sessionWebhook: string;
/**
* 当前会话的 Webhook 地址过期时间
*/
sessionWebhookExpiredTime: number;
};
export declare const StreamClient: typeof EventBus.StreamClient;
declare class StreamClient_2 extends EventEmitter {
#private;
protected client: DingtalkClient;
constructor(client: DingtalkClient, options?: StreamClientOptions);
connect(): Promise;
isConnecting(): boolean;
disconnect(): void;
sendGraphAPIResponse(messageId: string, value: GraphAPIResponse): void;
onImMessage(callback: (message: IncomingMessage) => void): void;
protected handleSystem(message: SubscriptionData): void;
protected handleCallback(event: SubscriptionData): void;
protected handleEvent(event: SubscriptionData): void;
protected getEndpoint(): Promise;
protected enableHeartbeat(): void;
protected disableHeartbeat(): void;
authHeaders(): Promise<{
'access-token': string;
}>;
protected defaultHeaders(): Promise<{
'access-token': string;
Accept: string;
'Content-Type': string;
}>;
}
declare interface StreamClientOptions {
/**
* 订阅的事件
*/
subscriptions?: SubscriptionItem[];
/**
* ping 服务器的默认间隔
*
* @defaultValue 8 * 1000
*/
keepAliveIntervalInMilliseconds?: number;
}
declare type SubscriptionData = {
specVersion: string;
type: string;
headers: {
appId: string;
connectionId: string;
IncomingType: string;
messageId: string;
time: string;
topic: string;
eventType?: string;
eventBornTime?: string;
eventId?: string;
eventCorpId?: string;
eventUnifiedAppId?: string;
};
data: string;
};
declare type SubscriptionItem = {
type: (string & NonNullable) | 'EVENT' | 'CALLBACK';
topic: string;
};
declare class SubscriptionManager {
}
declare const Subscriptions: {
readonly AllEvent: SubscriptionItem;
readonly ImMessage: SubscriptionItem;
};
export declare const SubscriptionType: typeof EventBus.SubscriptionType;
declare enum SubscriptionType_2 {
ImMessage = "im.message"
}
declare class Talker {
protected incoming: IncomingMessage;
/**
* 用户ID
*
*/
id: string;
/**
* 企业ID
*/
corpId: string;
/**
* 员工ID
*/
staffId: string;
/**
* 昵称
*/
name: string;
/**
* 是否管理员
*/
isAdmin: boolean;
constructor(incoming: IncomingMessage, properties: TalkerProperties);
reply(sayable: Sayable): Promise;
}
declare type TalkerProperties = {
/**
* 用户ID
*/
senderId: string;
/**
* 企业ID
*/
senderCorpId: string;
/**
* 员工ID
*/
senderStaffId: string;
/**
* 昵称
*/
senderNick: string;
/**
* 是否管理员
*/
isAdmin: boolean;
};
declare type TokenResponse = {
errcode: number;
errmsg: string;
access_token: string;
expires_in: number;
};
export declare const UnprocessableEntityError: typeof Errors.UnprocessableEntityError;
declare class UnprocessableEntityError_2 extends APIError_2 {
readonly status = 422;
}
export declare const Uploader: typeof API.Uploader;
declare class Uploader_2 extends APIResource {
endpoint: string;
/**
* 从远程链接获取文件并上传
*
* @param type - 媒体文件类型
* @param url - 下载地址
* @param name - 文件名
* @returns 上传结果
*/
putFromURL(type: Type, url: string, name?: string): Promise>;
/**
* 从本地文件上传
*
* @param type - 上传文件类型
* @param path - 文件路径
* @param filename - 文件名
* @returns 上传结果
*/
putFromPath(type: Type, path: string, name?: string): Promise>;
/**
* 从文件内容上传
*
* @see https://open.dingtalk.com/document/orgapp/upload-media-files
* @param type - 上传类型
* @param data - 文件内容
* @param filename - 文件名
* @returns 上传结果
*/
putFromObject(type: Type, data: BlobPart, filename?: string): Promise>;
}
/**
* 上传结果
*/
declare type UploadResult = {
/**
* 错误码
*/
errcode: number;
/**
* 错误信息
*/
errmsg: string;
/**
* 媒体文件类型
*/
type: T;
/**
* 媒体文件上传后获取的唯一标识。
*/
media_id: string;
/**
* 媒体文件上传时间戳。
*/
created_at: number;
};
export { }