UNPKG

n8n-nodes-wechat-publish

Version:

N8N nodes for WeChat Official Account publishing - Create drafts and publish articles to WeChat Official Account platform

132 lines (131 loc) 4.09 kB
import { WeChatApiConfig, CreateDraftResponse, GetDraftResponse, PublishResponse, PublishStatusResponse, MediaUploadResponse, WeChatApiResponse, DraftArticle, GetMaterialListResponse, BatchUploadMemesResponse, ImageInsertionConfig, ContentProcessingResult } from '../../types'; /** * WeChat API Client for managing drafts and publishing articles */ export declare class WeChatApiClient { private config; private httpClient; private accessToken; private tokenExpiryTime; constructor(config: WeChatApiConfig); /** * Ensure access token is valid and refresh if necessary */ private ensureValidToken; /** * Refresh access token from WeChat API */ private refreshAccessToken; /** * Create a new draft article */ createDraft(articles: DraftArticle[]): Promise<CreateDraftResponse>; /** * Get an existing draft article */ getDraft(mediaId: string): Promise<GetDraftResponse>; /** * Delete an existing draft article */ deleteDraft(mediaId: string): Promise<WeChatApiResponse>; /** * Publish a draft article */ publishDraft(mediaId: string): Promise<PublishResponse>; /** * Get publishing status of an article */ getPublishStatus(publishId: string): Promise<PublishStatusResponse>; /** * Upload media file (image/thumbnail) */ uploadMedia(fileBuffer: Buffer, mimeType: string, mediaType?: string): Promise<MediaUploadResponse>; /** * Get file extension from MIME type */ private getFileExtension; /** * Validate WeChat API response for errors */ private validateResponse; /** * Get current access token (for debugging purposes) */ getAccessToken(): string | null; /** * Get material list (images, videos, voices, news) */ getMaterialList(type: string, offset?: number, count?: number): Promise<GetMaterialListResponse>; /** * Check if access token is valid */ isTokenValid(): boolean; /** * Batch upload memes from Meme API to WeChat */ batchUploadMemes(count?: number, subreddit?: string, skipNsfw?: boolean, skipSpoiler?: boolean, minUps?: number): Promise<BatchUploadMemesResponse>; /** * Fetch memes from Meme API */ private fetchMemesFromApi; /** * Filter memes based on criteria */ private filterMemes; /** * Remove duplicate memes based on URL */ private removeDuplicateMemes; /** * Download image from URL */ private downloadImage; /** * Process content and insert images intelligently */ processContentWithImages(content: string, config: ImageInsertionConfig): ContentProcessingResult; /** * Create a draft article with automatic image integration from batch upload */ createDraftWithBatchImages(article: DraftArticle, imageConfig?: ImageInsertionConfig): Promise<CreateDraftResponse & { image_integration_info?: any; }>; /** * Automatically insert images at strategic positions */ private insertImagesAutomatically; /** * Insert images by paragraph breaks */ private insertImagesByParagraph; /** * Calculate optimal insertion points for images */ private calculateInsertionPoints; /** * Select image based on strategy */ private selectImageByStrategy; /** * Find insertion position in HTML content */ private findInsertionPositionInHtml; /** * Extract first and last words for partial matching */ private getFirstAndLastWords; /** * Find the next suitable insertion point */ private findNextInsertionPoint; /** * Find insertion point at paragraph boundaries as fallback */ private findParagraphInsertionPoint; /** * Generate WeChat compatible image HTML * @param imageUrlOrMediaId - Either a full URL from Get Material List or a media_id * @param imageType - Image type (png, jpg, etc.) */ private generateWeChatImageHtml; }