UNPKG

@baileys-md/baileys

Version:

Baileys WhatsApp API

130 lines (120 loc) 4.74 kB
//========================================// import { makeLibSignalRepository } from "../Signal/libsignal.js"; import { Browsers } from "../Utils/browser-utils.js"; import { proto } from "../../WAProto/index.js"; import logger from "../Utils/logger.js"; export const version = [2, 3000, 1033846690] const URL = "https://raw.githubusercontent.com/WhiskeySockets/Baileys/master/src/Defaults/index.ts"; const response = await fetch(URL, { method: "GET" }); const text = await response.text(); const lines = text.split("\n"); const versionLine = lines[6]; const versionMatch = versionLine.match(/const version = \[(\d+),\s*(\d+),\s*(\d+)\]/); const version_2 = [parseInt(versionMatch[1]), parseInt(versionMatch[2]), parseInt(versionMatch[3])]; export const DICT_VERSION = 3; export const NOISE_WA_HEADER = Buffer.from([87, 65, 6, DICT_VERSION]); export const CALL_VIDEO_PREFIX = "https://call.whatsapp.com/video/"; export const CALL_AUDIO_PREFIX = "https://call.whatsapp.com/voice/"; export const WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX = Buffer.from([6, 5]); export const WA_ADV_HOSTED_DEVICE_SIG_PREFIX = Buffer.from([6, 6]); export const NOISE_MODE = "Noise_XX_25519_AESGCM_SHA256\0\0\0\0"; export const WA_ADV_ACCOUNT_SIG_PREFIX = Buffer.from([6, 0]); export const WA_ADV_DEVICE_SIG_PREFIX = Buffer.from([6, 1]); export const DEFAULT_ORIGIN = "https://web.whatsapp.com"; export const WA_DEFAULT_EPHEMERAL = 7 * 24 * 60 * 60; export const UNAUTHORIZED_CODES = [401, 403, 419]; export const KEY_BUNDLE_TYPE = Buffer.from([5]); export const PHONE_CONNECTION_CB = "CB:Pong"; export const DEF_CALLBACK_PREFIX = "CB:"; export const DEF_TAG_PREFIX = "TAG:"; export const URL_REGEX = /https:\/\/(?![^:@\/\s]+:[^:@\/\s]+@)[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}(:\d+)?(\/[^\s]*)?/g; export const WA_CERT_DETAILS = { SERIAL: 0 }; export const PROCESSABLE_HISTORY_TYPES = [ proto.Message.HistorySyncNotification.HistorySyncType.INITIAL_BOOTSTRAP, proto.Message.HistorySyncNotification.HistorySyncType.PUSH_NAME, proto.Message.HistorySyncNotification.HistorySyncType.RECENT, proto.Message.HistorySyncNotification.HistorySyncType.FULL, proto.Message.HistorySyncNotification.HistorySyncType.ON_DEMAND, proto.Message.HistorySyncNotification.HistorySyncType.NON_BLOCKING_DATA, proto.Message.HistorySyncNotification.HistorySyncType.INITIAL_STATUS_V3 ]; export const DEFAULT_CONNECTION_CONFIG = { "version": version, "browser": Browsers.iOS("Safari"), "waWebSocketUrl": "wss://web.whatsapp.com/ws/chat", "connectTimeoutMs": 20000, "keepAliveIntervalMs": 5000, "logger": logger.child({ "class": "baileys" }), "emitOwnEvents": true, "defaultQueryTimeoutMs": 60000, "customUploadHosts": [], "retryRequestDelayMs": 250, "maxMsgRetryCount": 5, "fireInitQueries": true, "auth": undefined, "markOnlineOnConnect": true, "syncFullHistory": true, "patchMessageBeforeSending": msg => msg, "shouldSyncHistoryMessage": () => true, "shouldIgnoreJid": () => false, "linkPreviewImageThumbnailWidth": 192, "transactionOpts": { "maxCommitRetries": 10, "delayBetweenTriesMs": 3000 }, "generateHighQualityLinkPreview": true, "enableAutoSessionRecreation": false, "enableRecentMessageCache": false, "options": {}, "appStateMacVerification": { "patch": false, "snapshot": false }, "countryCode": "US", "getMessage": async () => undefined, "cachedGroupMetadata": async () => undefined, "makeSignalRepository": makeLibSignalRepository }; export const MEDIA_PATH_MAP = { "image": "/mms/image", "video": "/mms/video", "document": "/mms/document", "audio": "/mms/audio", "sticker": "/mms/image", "thumbnail-link": "/mms/image", "product-catalog-image": "/product/image", "md-app-state": "", "md-msg-hist": "/mms/md-app-state", "biz-cover-photo": "/pps/biz-cover-photo" }; export const MEDIA_HKDF_KEY_MAPPING = { "audio": "Audio", "document": "Document", "gif": "Video", "image": "Image", "ppic": "", "product": "Image", "ptt": "Audio", "sticker": "Image", "video": "Video", "thumbnail-document": "Document Thumbnail", "thumbnail-image": "Image Thumbnail", "thumbnail-video": "Video Thumbnail", "thumbnail-link": "Link Thumbnail", "md-msg-hist": "History", "md-app-state": "App State", "product-catalog-image": "", "payment-bg-image": "Payment Background", "ptv": "Video", "biz-cover-photo": "Image" }; export const MEDIA_KEYS = Object.keys(MEDIA_PATH_MAP); export const MIN_PREKEY_COUNT = 2; export const INITIAL_PREKEY_COUNT = 2; export const UPLOAD_TIMEOUT = 30000; export const MIN_UPLOAD_INTERVAL = 5000; export const DEFAULT_CACHE_TTLS = { SIGNAL_STORE: 5 * 60, MSG_RETRY: 60 * 60, CALL_OFFER: 5 * 60, USER_DEVICES: 5 * 60 };