@queenanya/baileys 7.3.7 → 7.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +941 -0
- package/WAProto/GenerateStatics.sh +4 -0
- package/WAProto/WAProto.proto +3344 -0
- package/WAProto/index.d.ts +37016 -0
- package/WAProto/index.js +101044 -0
- package/WASignalGroup/GroupProtocol.js +1697 -0
- package/WASignalGroup/ciphertext_message.js +16 -0
- package/WASignalGroup/group_cipher.js +120 -0
- package/WASignalGroup/group_session_builder.js +46 -0
- package/WASignalGroup/index.js +5 -0
- package/WASignalGroup/keyhelper.js +21 -0
- package/WASignalGroup/protobufs.js +3 -0
- package/WASignalGroup/queue_job.js +69 -0
- package/WASignalGroup/sender_chain_key.js +50 -0
- package/WASignalGroup/sender_key_distribution_message.js +78 -0
- package/WASignalGroup/sender_key_message.js +92 -0
- package/WASignalGroup/sender_key_name.js +70 -0
- package/WASignalGroup/sender_key_record.js +56 -0
- package/WASignalGroup/sender_key_state.js +129 -0
- package/WASignalGroup/sender_message_key.js +39 -0
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/index.d.ts +284 -0
- package/lib/Defaults/index.js +122 -0
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Signal/libsignal.d.ts +3 -0
- package/lib/Signal/libsignal.js +152 -0
- package/lib/Socket/Client/abstract-socket-client.d.ts +17 -0
- package/lib/Socket/Client/abstract-socket-client.js +13 -0
- package/lib/Socket/Client/index.d.ts +3 -0
- package/lib/Socket/Client/index.js +19 -0
- package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
- package/lib/Socket/Client/mobile-socket-client.js +65 -0
- package/lib/Socket/Client/web-socket-client.d.ts +12 -0
- package/lib/Socket/Client/web-socket-client.js +62 -0
- package/lib/Socket/business.d.ts +177 -0
- package/lib/Socket/business.js +260 -0
- package/lib/Socket/chats.d.ts +91 -0
- package/lib/Socket/chats.js +950 -0
- package/lib/Socket/groups.d.ts +137 -0
- package/lib/Socket/groups.js +314 -0
- package/lib/Socket/index.d.ts +179 -0
- package/lib/Socket/index.js +10 -0
- package/lib/Socket/messages-recv.d.ts +164 -0
- package/lib/Socket/messages-recv.js +921 -0
- package/lib/Socket/messages-send.d.ts +157 -0
- package/lib/Socket/messages-send.js +779 -0
- package/lib/Socket/newsletter.d.ts +143 -0
- package/lib/Socket/newsletter.js +249 -0
- package/lib/Socket/registration.d.ts +271 -0
- package/lib/Socket/registration.js +166 -0
- package/lib/Socket/socket.d.ts +44 -0
- package/lib/Socket/socket.js +620 -0
- package/lib/Store/index.d.ts +3 -0
- package/lib/Store/index.js +10 -0
- package/lib/Store/make-cache-manager-store.d.ts +14 -0
- package/lib/Store/make-cache-manager-store.js +83 -0
- package/lib/Store/make-in-memory-store.d.ts +118 -0
- package/lib/Store/make-in-memory-store.js +422 -0
- package/lib/Store/make-ordered-dictionary.d.ts +13 -0
- package/lib/Store/make-ordered-dictionary.js +81 -0
- package/lib/Store/object-repository.d.ts +10 -0
- package/lib/Store/object-repository.js +27 -0
- package/lib/Types/Auth.d.ts +111 -0
- package/lib/Types/Auth.js +2 -0
- package/lib/Types/Call.d.ts +13 -0
- package/lib/Types/Call.js +2 -0
- package/lib/Types/Chat.d.ts +107 -0
- package/lib/Types/Chat.js +4 -0
- package/lib/Types/Contact.d.ts +19 -0
- package/lib/Types/Contact.js +2 -0
- package/lib/Types/Events.d.ts +199 -0
- package/lib/Types/Events.js +2 -0
- package/lib/Types/GroupMetadata.d.ts +56 -0
- package/lib/Types/GroupMetadata.js +2 -0
- package/lib/Types/Label.d.ts +46 -0
- package/lib/Types/Label.js +27 -0
- package/lib/Types/LabelAssociation.d.ts +29 -0
- package/lib/Types/LabelAssociation.js +9 -0
- package/lib/Types/Message.d.ts +278 -0
- package/lib/Types/Message.js +9 -0
- package/lib/Types/Newsletter.d.ts +79 -0
- package/lib/Types/Newsletter.js +18 -0
- package/lib/Types/Product.d.ts +78 -0
- package/lib/Types/Product.js +2 -0
- package/lib/Types/Signal.d.ts +57 -0
- package/lib/Types/Signal.js +2 -0
- package/lib/Types/Socket.d.ts +118 -0
- package/lib/Types/Socket.js +2 -0
- package/lib/Types/State.d.ts +27 -0
- package/lib/Types/State.js +2 -0
- package/lib/Types/index.d.ts +65 -0
- package/lib/Types/index.js +42 -0
- package/lib/Utils/auth-utils.d.ts +18 -0
- package/lib/Utils/auth-utils.js +206 -0
- package/lib/Utils/baileys-event-stream.d.ts +16 -0
- package/lib/Utils/baileys-event-stream.js +63 -0
- package/lib/Utils/business.d.ts +22 -0
- package/lib/Utils/business.js +234 -0
- package/lib/Utils/chat-utils.d.ts +72 -0
- package/lib/Utils/chat-utils.js +740 -0
- package/lib/Utils/crypto.d.ts +42 -0
- package/lib/Utils/crypto.js +153 -0
- package/lib/Utils/decode-wa-message.d.ts +20 -0
- package/lib/Utils/decode-wa-message.js +207 -0
- package/lib/Utils/event-buffer.d.ts +35 -0
- package/lib/Utils/event-buffer.js +520 -0
- package/lib/Utils/generics.d.ts +115 -0
- package/lib/Utils/generics.js +440 -0
- package/lib/Utils/history.d.ts +19 -0
- package/lib/Utils/history.js +94 -0
- package/lib/Utils/index.d.ts +17 -0
- package/lib/Utils/index.js +33 -0
- package/lib/Utils/link-preview.d.ts +21 -0
- package/lib/Utils/link-preview.js +93 -0
- package/lib/Utils/logger.d.ts +2 -0
- package/lib/Utils/logger.js +7 -0
- package/lib/Utils/lt-hash.d.ts +12 -0
- package/lib/Utils/lt-hash.js +51 -0
- package/lib/Utils/make-mutex.d.ts +7 -0
- package/lib/Utils/make-mutex.js +43 -0
- package/lib/Utils/messages-media.d.ts +131 -0
- package/lib/Utils/messages-media.js +793 -0
- package/lib/Utils/messages.d.ts +78 -0
- package/lib/Utils/messages.js +771 -0
- package/lib/Utils/noise-handler.d.ts +22 -0
- package/lib/Utils/noise-handler.js +155 -0
- package/lib/Utils/process-message.d.ts +42 -0
- package/lib/Utils/process-message.js +354 -0
- package/lib/Utils/signal.d.ts +32 -0
- package/lib/Utils/signal.js +156 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +12 -0
- package/lib/Utils/use-multi-file-auth-state.js +93 -0
- package/lib/Utils/validate-connection.d.ts +11 -0
- package/lib/Utils/validate-connection.js +205 -0
- package/lib/WABinary/constants.d.ts +27 -0
- package/lib/WABinary/constants.js +40 -0
- package/lib/WABinary/decode.d.ts +8 -0
- package/lib/WABinary/decode.js +254 -0
- package/lib/WABinary/encode.d.ts +2 -0
- package/lib/WABinary/encode.js +228 -0
- package/lib/WABinary/generic-utils.d.ts +16 -0
- package/lib/WABinary/generic-utils.js +110 -0
- package/lib/WABinary/index.d.ts +5 -0
- package/lib/WABinary/index.js +21 -0
- package/lib/WABinary/jid-utils.d.ts +31 -0
- package/lib/WABinary/jid-utils.js +62 -0
- package/lib/WABinary/types.d.ts +18 -0
- package/lib/WABinary/types.js +2 -0
- package/lib/WAM/BinaryInfo.d.ts +18 -0
- package/lib/WAM/BinaryInfo.js +13 -0
- package/lib/WAM/constants.d.ts +38 -0
- package/lib/WAM/constants.js +15350 -0
- package/lib/WAM/encode.d.ts +4 -0
- package/lib/WAM/encode.js +155 -0
- package/lib/WAM/index.d.ts +3 -0
- package/lib/WAM/index.js +19 -0
- package/lib/index.d.ts +11 -0
- package/lib/index.js +30 -0
- package/package.json +102 -2
- package/.anya-md/.replit +0 -2
- package/.anya-md/.temp/.temp +0 -1
- package/.anya-md/Dockerfile +0 -16
- package/.anya-md/LICENCE +0 -674
- package/.anya-md/README.md +0 -301
- package/.anya-md/app.json +0 -81
- package/.anya-md/config.js +0 -74
- package/.anya-md/heroku.yml +0 -5
- package/.anya-md/index.js +0 -47
- package/.anya-md/koyeb.yaml +0 -14
- package/.anya-md/lib/.dev.js +0 -47
- package/.anya-md/lib/Assets/aliveMedia.mp4 +0 -0
- package/.anya-md/lib/Assets/goodbyeBG.jpg +0 -0
- package/.anya-md/lib/Assets/image_1.jpg +0 -0
- package/.anya-md/lib/Assets/image_2.jpg +0 -0
- package/.anya-md/lib/Assets/menuMedia.mp4 +0 -0
- package/.anya-md/lib/Assets/ownerMentionMp3.mp3 +0 -0
- package/.anya-md/lib/Assets/port.html +0 -36
- package/.anya-md/lib/Assets/reaction/angry/angry108202410.jpeg +0 -0
- package/.anya-md/lib/Assets/reaction/angry/angry108202412.jpeg +0 -0
- package/.anya-md/lib/Assets/reaction/angry/angry108202413.jpeg +0 -0
- package/.anya-md/lib/Assets/reaction/angry/angry108202414.jpeg +0 -0
- package/.anya-md/lib/Assets/reaction/angry/angry108202415.jpeg +0 -0
- package/.anya-md/lib/Assets/reaction/angry/angry108202416.jpeg +0 -0
- package/.anya-md/lib/Assets/reaction/angry/angry108202417.jpeg +0 -0
- package/.anya-md/lib/Assets/reaction/angry/angry108202418.jpeg +0 -0
- package/.anya-md/lib/Assets/reaction/angry/angry108202419.jpeg +0 -0
- package/.anya-md/lib/Assets/reaction/angry/angry108202420.jpeg +0 -0
- package/.anya-md/lib/Assets/reaction/angry/angry108202421.jpeg +0 -0
- package/.anya-md/lib/Assets/reaction/angry/angry108202423.jpeg +0 -0
- package/.anya-md/lib/Assets/reaction/angry/angry108202425.jpeg +0 -0
- package/.anya-md/lib/Assets/reaction/angry/angry108202426.jpeg +0 -0
- package/.anya-md/lib/Assets/reaction/angry/angry108202427.jpeg +0 -0
- package/.anya-md/lib/Assets/reaction/angry/angry108202428.jpeg +0 -0
- package/.anya-md/lib/Assets/reaction/angry/angry108202429.jpeg +0 -0
- package/.anya-md/lib/Assets/reaction/angry/angry108202430.jpeg +0 -0
- package/.anya-md/lib/Assets/reaction/angry/angry108202431.jpeg +0 -0
- package/.anya-md/lib/Assets/reaction/angry/angry108202469.jpeg +0 -0
- package/.anya-md/lib/Assets/reaction/angry/angry10820249.jpeg +0 -0
- package/.anya-md/lib/Assets/reaction/angry/angry11.mp4 +0 -0
- package/.anya-md/lib/Assets/reaction/angry/angry12.mp4 +0 -0
- package/.anya-md/lib/Assets/reaction/angry/angry14.jpg +0 -0
- package/.anya-md/lib/Assets/reaction/angry/angry2.mp4 +0 -0
- package/.anya-md/lib/Assets/reaction/angry/angry3.mp4 +0 -0
- package/.anya-md/lib/Assets/reaction/angry/angry5.jpg +0 -0
- package/.anya-md/lib/Assets/reaction/angry/angry6.png +0 -0
- package/.anya-md/lib/Assets/reaction/angry/angry8.png +0 -0
- package/.anya-md/lib/Assets/reaction/angry/angry9.jpg +0 -0
- package/.anya-md/lib/Assets/reaction/confused/confused1.png +0 -0
- package/.anya-md/lib/Assets/reaction/confused/confused2.jpg +0 -0
- package/.anya-md/lib/Assets/reaction/confused/confused3.jpg +0 -0
- package/.anya-md/lib/Assets/reaction/confused/confused4.mp4 +0 -0
- package/.anya-md/lib/Assets/reaction/confused/confused5.jpg +0 -0
- package/.anya-md/lib/Assets/reaction/confused/confused6.webp +0 -0
- package/.anya-md/lib/Assets/reaction/confused/confused7.png +0 -0
- package/.anya-md/lib/Assets/reaction/confused/confused8.jpg +0 -0
- package/.anya-md/lib/Assets/reaction/cry/cry1.jpeg +0 -0
- package/.anya-md/lib/Assets/reaction/cry/cry12.jpeg +0 -0
- package/.anya-md/lib/Assets/reaction/cry/cry13.jpeg +0 -0
- package/.anya-md/lib/Assets/reaction/cry/cry14.jpeg +0 -0
- package/.anya-md/lib/Assets/reaction/cry/cry15.jpeg +0 -0
- package/.anya-md/lib/Assets/reaction/cry/cry16.jpeg +0 -0
- package/.anya-md/lib/Assets/reaction/cry/cry17.jpeg +0 -0
- package/.anya-md/lib/Assets/reaction/cry/cry18.jpeg +0 -0
- package/.anya-md/lib/Assets/reaction/cry/cry19.jpeg +0 -0
- package/.anya-md/lib/Assets/reaction/cry/cry22.jpeg +0 -0
- package/.anya-md/lib/Assets/reaction/cry/cry23.jpeg +0 -0
- package/.anya-md/lib/Assets/reaction/cry/cry5.jpeg +0 -0
- package/.anya-md/lib/Assets/reaction/cry/cry9.jpeg +0 -0
- package/.anya-md/lib/Assets/reaction/happy/happyrect1.jpeg +0 -0
- package/.anya-md/lib/Assets/reaction/no/_pika +0 -1
- package/.anya-md/lib/Assets/reaction/no/no1.jpg +0 -0
- package/.anya-md/lib/Assets/reaction/no/no2.png +0 -0
- package/.anya-md/lib/Assets/reaction/no/no3.jpg +0 -0
- package/.anya-md/lib/Assets/reaction/no/no4.png +0 -0
- package/.anya-md/lib/Assets/reaction/no/no5.png +0 -0
- package/.anya-md/lib/Assets/reaction/no/no6.jpg +0 -0
- package/.anya-md/lib/Assets/reaction/no/no7.jpg +0 -0
- package/.anya-md/lib/Assets/reaction/no/no8.jpg +0 -0
- package/.anya-md/lib/Assets/reaction/no/no9.mp4 +0 -0
- package/.anya-md/lib/Assets/reaction/smug/059e1bdc-e62a-4943-b85e-ea372709f6a7.jpeg +0 -0
- package/.anya-md/lib/Assets/reaction/smug/8fda90b3-bc98-4d24-ac10-4402c4e7be93.jpeg +0 -0
- package/.anya-md/lib/Assets/reaction/smug/Aqua.jpeg +0 -0
- package/.anya-md/lib/Assets/reaction/smug/Karasuma Chitose.jpeg +0 -0
- package/.anya-md/lib/Assets/reaction/smug/Smug Face - Fibel Sistine.jpeg +0 -0
- package/.anya-md/lib/Assets/reaction/smug/bf8d78ec-4fcc-4ff7-b3c3-91a0c5f22567.jpeg +0 -0
- package/.anya-md/lib/Assets/reaction/smug//330/247/330/255/331/204/330/247/331/213 /330/247/330/250/330/252/330/263/330/247/331/205/331/207 /330/264/330/261/331/212/330/261/331/207/360/237/230/255/360/237/230/255/360/237/230/255.jpeg +0 -0
- package/.anya-md/lib/Assets/verifyIMG.jpg +0 -0
- package/.anya-md/lib/Assets/welcomeGIF.mp4 +0 -0
- package/.anya-md/lib/database/categories.json +0 -77
- package/.anya-md/lib/database/cooldown.json +0 -1
- package/.anya-md/lib/database/disk/main.js +0 -43
- package/.anya-md/lib/database/emoji.js +0 -23
- package/.anya-md/lib/database/games/quiz/Questions.js +0 -44
- package/.anya-md/lib/database/games/quiz/Quiz.js +0 -169
- package/.anya-md/lib/database/games/quiz/database.json +0 -1
- package/.anya-md/lib/database/games/quiz/index.js +0 -7
- package/.anya-md/lib/database/json/.pika.js +0 -3
- package/.anya-md/lib/database/json/animeQuotes.json +0 -51062
- package/.anya-md/lib/database/json/bioQuotes.json +0 -5744
- package/.anya-md/lib/database/json/cogan.json +0 -102
- package/.anya-md/lib/database/json/countries.json +0 -21210
- package/.anya-md/lib/database/json/countries2.json +0 -1
- package/.anya-md/lib/database/json/couplepp.json +0 -725
- package/.anya-md/lib/database/json/flaming.json +0 -7
- package/.anya-md/lib/database/json/ganpati.json +0 -102
- package/.anya-md/lib/database/json/husbu.json +0 -1967
- package/.anya-md/lib/database/json/islamicWall.json +0 -501
- package/.anya-md/lib/database/json/pickupLines.json +0 -118
- package/.anya-md/lib/database/json/shreeram.json +0 -49
- package/.anya-md/lib/database/json/truthDare.json +0 -643
- package/.anya-md/lib/database/mongodb/README.md +0 -142
- package/.anya-md/lib/database/mongodb/bot.js +0 -12
- package/.anya-md/lib/database/mongodb/cmd.js +0 -17
- package/.anya-md/lib/database/mongodb/group.js +0 -22
- package/.anya-md/lib/database/mongodb/index.js +0 -24
- package/.anya-md/lib/database/mongodb/plugins.js +0 -124
- package/.anya-md/lib/database/mongodb/system.js +0 -34
- package/.anya-md/lib/database/mongodb/ui.js +0 -15
- package/.anya-md/lib/database/mongodb/user.js +0 -17
- package/.anya-md/lib/database/mongodb/warn.js +0 -136
- package/.anya-md/lib/database/sessions/.pika.js +0 -3
- package/.anya-md/lib/frameworks/index.js +0 -5
- package/.anya-md/lib/frameworks/reactionMedia.js +0 -91
- package/.anya-md/lib/lib/README.md +0 -29
- package/.anya-md/lib/lib/ai/README.md +0 -35
- package/.anya-md/lib/lib/ai/aiArt.js +0 -47
- package/.anya-md/lib/lib/ai/index.js +0 -7
- package/.anya-md/lib/lib/buttons.js +0 -530
- package/.anya-md/lib/lib/connectionMsg.js +0 -72
- package/.anya-md/lib/lib/converter.js +0 -355
- package/.anya-md/lib/lib/cooldown.js +0 -46
- package/.anya-md/lib/lib/events.js +0 -47
- package/.anya-md/lib/lib/functions.js +0 -47
- package/.anya-md/lib/lib/greeting.js +0 -115
- package/.anya-md/lib/lib/index.js +0 -381
- package/.anya-md/lib/lib/logger.js +0 -7
- package/.anya-md/lib/lib/maker/remini.js +0 -35
- package/.anya-md/lib/lib/mongoUrlFix.js +0 -46
- package/.anya-md/lib/lib/myfunc.js +0 -47
- package/.anya-md/lib/lib/plugins.js +0 -20
- package/.anya-md/lib/lib/prefix.js +0 -47
- package/.anya-md/lib/lib/scraper/README.md +0 -35
- package/.anya-md/lib/lib/scraper/SoundCloud.js +0 -47
- package/.anya-md/lib/lib/scraper/WebToons.js +0 -47
- package/.anya-md/lib/lib/scraper/android1.js +0 -47
- package/.anya-md/lib/lib/scraper/happymodSearch.js +0 -47
- package/.anya-md/lib/lib/scraper/index.js +0 -27
- package/.anya-md/lib/lib/scraper/konaChanSearch.js +0 -47
- package/.anya-md/lib/lib/scraper/pinterest.js +0 -47
- package/.anya-md/lib/lib/scraper/playstore.js +0 -47
- package/.anya-md/lib/lib/scraper/ringtone.js +0 -47
- package/.anya-md/lib/lib/scraper/steam.js +0 -47
- package/.anya-md/lib/lib/scraper/trendingTwitter.js +0 -51
- package/.anya-md/lib/lib/scraper/wattpad.js +0 -61
- package/.anya-md/lib/lib/scraper/wikipediaSearch.js +0 -42
- package/.anya-md/lib/lib/scraper.js +0 -47
- package/.anya-md/lib/lib/session.js +0 -47
- package/.anya-md/lib/lib/session2.js +0 -47
- package/.anya-md/lib/lib/similar.js +0 -47
- package/.anya-md/lib/lib/stylish-font.js +0 -2302
- package/.anya-md/lib/lib/unicode.js +0 -877
- package/.anya-md/lib/lib/upload/index.js +0 -3
- package/.anya-md/lib/lib/upload/webp2mp4File.js +0 -56
- package/.anya-md/lib/lib/ytdl-core.js +0 -47
- package/.anya-md/lib/plugins/README.md +0 -83
- package/.anya-md/lib/plugins/_menu.js +0 -810
- package/.anya-md/lib/plugins/_plugins.js +0 -239
- package/.anya-md/lib/plugins/admins.js +0 -689
- package/.anya-md/lib/plugins/ai.js +0 -160
- package/.anya-md/lib/plugins/autoreply.js +0 -101
- package/.anya-md/lib/plugins/broadcast.js +0 -204
- package/.anya-md/lib/plugins/convert.js +0 -293
- package/.anya-md/lib/plugins/core.js +0 -941
- package/.anya-md/lib/plugins/download.js +0 -373
- package/.anya-md/lib/plugins/fun.js +0 -75
- package/.anya-md/lib/plugins/games.js +0 -33
- package/.anya-md/lib/plugins/gcswitches.js +0 -204
- package/.anya-md/lib/plugins/general.js +0 -456
- package/.anya-md/lib/plugins/maker.js +0 -41
- package/.anya-md/lib/plugins/owner.js +0 -1049
- package/.anya-md/lib/plugins/religious.js +0 -81
- package/.anya-md/lib/plugins/search.js +0 -902
- package/.anya-md/lib/plugins/stalker.js +0 -187
- package/.anya-md/lib/plugins/sticker.js +0 -125
- package/.anya-md/lib/plugins/tools.js +0 -193
- package/.anya-md/lib/plugins/youtube.js +0 -204
- package/.anya-md/package.json +0 -75
- package/.anya-md/railway.json +0 -12
- package/.anya-md/render.yaml +0 -48
- package/.anya-md/replit.nix +0 -18
- package/.bash_history +0 -500
- package/.config/gh/config.yml +0 -19
- package/.config/gh/hosts.yml +0 -11
- package/.config/ngrok/ngrok.yml +0 -3
- package/.config/yarn/global/package.json +0 -5
- package/.gitconfig +0 -772
- package/.node_repl_history +0 -0
- package/.npm/_cacache/content-v2/sha512/02/b3/d1abf5af06222f7de440ab1b057deb21f9dfb0ce0a8f5064b2ba00595933bbcbbaa040b4616f951d9f8ba48d67491df1198a4831fbd8ee26eb27dde36511 +0 -0
- package/.npm/_cacache/content-v2/sha512/49/7b/0cdbb4861f7c9358a7367ca478498371b269efb8143d75de901ed1169a267f56a68e60f008952f3ebcc727dbb60bb401011af3514a1dd33cdbed8d981fa8 +0 -0
- package/.npm/_cacache/content-v2/sha512/54/3a/647bceb49b7632e6e700cb9f1b66f0f528d4ca71f4f73e76a1e7c8c50b563a2d0bb7734c18f93e6c03b7ea93167db35db0e1999ab13b08ed6b250eed2d2a +0 -1
- package/.npm/_cacache/content-v2/sha512/56/7c/4d5820233a7278225351642f7355d9889af42e7efbbfe27d6b201727efad972a59fa32063c7e1159d01dbf27ba014095ca1349ec0d0767746c39441178fa +0 -1
- package/.npm/_cacache/content-v2/sha512/89/88/d295c7e4f4d0f4621676d4c499bea2a1c72b0c31a84ff78a8bb8f83042da2bcf596e664c021d21025b296cdd4aecb57a036ea366e39466df5a129fa471df +0 -0
- package/.npm/_cacache/content-v2/sha512/8b/46/42882ebb46a975b0ce6b9cdea357190c41b51bb59a21df41c575418850b28115921e130709846d8ff9cabeae72544ec37a48ee7ccb074fe94da925250e55 +0 -1
- package/.npm/_cacache/content-v2/sha512/dd/0d/f856b793da0619d18260556498dfff13391593abb6d6a582bf052f03ba35a03a1444bf5c2d40b7515d268ec2cb3e67a17a42f09f5e668c3bb9b743e3b8a7 +0 -1
- package/.npm/_cacache/content-v2/sha512/dd/15/702501c36ce653a003d2b101034a0cb9c0fd262fa77797f1a286a161a0b2dce51ef13199e9a3fa58008bdbbf4646a33b6f1a24a2807691093cb89beefb00 +0 -1
- package/.npm/_cacache/index-v5/35/f9/e8cc076ef93c1bc40804d3fe05171053366095c922f515b1fab2b580116f +0 -4
- package/.npm/_cacache/index-v5/6a/a2/780c77f928115d4dad58a9dc4fa241de8d914abfff994e44602cc93a697c +0 -2
- package/.npm/_cacache/index-v5/71/ba/d0bb16fddeb617bbbb3713f46750d1bf5b57742abb6feb6dee4d16c68da4 +0 -4
- package/.npm/_cacache/index-v5/72/ae/c69532318093b3bd13618450ca5c26adc018a4afc0e020786207068593cf +0 -2
- package/.npm/_cacache/index-v5/7e/5e/9683ad4854f4201d7e53bf9beb2aefafa7b1efbb2c6ac7b36b78d0b218c8 +0 -2
- package/.npm/_cacache/index-v5/eb/a0/19e529094c594367a9e1aa68096a313d3dc5509d410761bf50122826a6d2 +0 -4
- package/.npm/_cacache/index-v5/f1/fa/2d2f12de549683d1275ec0f2ff15610b408fd89d1b7a755ddb7b77c00371 +0 -2
- package/.npm/_logs/2024-10-03T05_52_01_853Z-debug-0.log +0 -52
- package/.npm/_logs/2024-10-03T05_52_08_135Z-debug-0.log +0 -52
- package/.npm/_logs/2024-10-03T05_52_14_087Z-debug-0.log +0 -52
- package/.npm/_logs/2024-10-03T05_52_22_730Z-debug-0.log +0 -52
- package/.npm/_logs/2024-10-03T05_52_29_410Z-debug-0.log +0 -52
- package/.npm/_logs/2024-10-03T05_52_35_375Z-debug-0.log +0 -52
- package/.npm/_logs/2024-10-03T15_32_57_465Z-debug-0.log +0 -20
- package/.npm/_logs/2024-10-10T05_40_23_847Z-debug-0.log +0 -254
- package/.npm/_logs/2024-10-10T05_40_50_397Z-debug-0.log +0 -73
- package/.npm/_logs/2024-10-10T05_40_59_931Z-debug-0.log +0 -52
- package/.npm/_logs/2024-10-10T05_42_07_969Z-debug-0.log +0 -52
- package/.pm2/logs/anya-error.log +0 -0
- package/.pm2/logs/anya-out.log +0 -59
- package/.pm2/logs/anya-v2-error.log +0 -2184
- package/.pm2/logs/anya-v2-out.log +0 -362
- package/.pm2/module_conf.json +0 -1
- package/.pm2/pm2.log +0 -919
- package/.pm2/pm2.pid +0 -1
- package/.pm2/touch +0 -1
- package/.ssh/authorized_keys +0 -0
- package/.termux/termux.properties +0 -180
- package/.wget-hsts +0 -5
|
@@ -0,0 +1,771 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.assertMediaContent = exports.downloadMediaMessage = exports.aggregateMessageKeysNotFromMe = exports.getAggregateVotesInPollMessage = exports.updateMessageWithPollUpdate = exports.updateMessageWithReaction = exports.updateMessageWithReceipt = exports.getDevice = exports.extractMessageContent = exports.normalizeMessageContent = exports.getContentType = exports.generateWAMessage = exports.generateWAMessageFromContent = exports.generateWAMessageContent = exports.generateForwardMessageContent = exports.prepareDisappearingMessageSettingContent = exports.prepareWAMessageMedia = exports.generateLinkPreviewIfRequired = exports.extractUrlFromText = void 0;
|
|
7
|
+
const boom_1 = require("@hapi/boom");
|
|
8
|
+
const axios_1 = __importDefault(require("axios"));
|
|
9
|
+
const crypto_1 = require("crypto");
|
|
10
|
+
const fs_1 = require("fs");
|
|
11
|
+
const WAProto_1 = require("../../WAProto");
|
|
12
|
+
const Defaults_1 = require("../Defaults");
|
|
13
|
+
const Types_1 = require("../Types");
|
|
14
|
+
const WABinary_1 = require("../WABinary");
|
|
15
|
+
const crypto_2 = require("./crypto");
|
|
16
|
+
const generics_1 = require("./generics");
|
|
17
|
+
const messages_media_1 = require("./messages-media");
|
|
18
|
+
const MIMETYPE_MAP = {
|
|
19
|
+
image: 'image/jpeg',
|
|
20
|
+
video: 'video/mp4',
|
|
21
|
+
document: 'application/pdf',
|
|
22
|
+
audio: 'audio/ogg; codecs=opus',
|
|
23
|
+
sticker: 'image/webp',
|
|
24
|
+
'product-catalog-image': 'image/jpeg',
|
|
25
|
+
};
|
|
26
|
+
const MessageTypeProto = {
|
|
27
|
+
'image': Types_1.WAProto.Message.ImageMessage,
|
|
28
|
+
'video': Types_1.WAProto.Message.VideoMessage,
|
|
29
|
+
'audio': Types_1.WAProto.Message.AudioMessage,
|
|
30
|
+
'sticker': Types_1.WAProto.Message.StickerMessage,
|
|
31
|
+
'document': Types_1.WAProto.Message.DocumentMessage,
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Uses a regex to test whether the string contains a URL, and returns the URL if it does.
|
|
35
|
+
* @param text eg. hello https://google.com
|
|
36
|
+
* @returns the URL, eg. https://google.com
|
|
37
|
+
*/
|
|
38
|
+
const extractUrlFromText = (text) => { var _a; return (_a = text.match(Defaults_1.URL_REGEX)) === null || _a === void 0 ? void 0 : _a[0]; };
|
|
39
|
+
exports.extractUrlFromText = extractUrlFromText;
|
|
40
|
+
const generateLinkPreviewIfRequired = async (text, getUrlInfo, logger) => {
|
|
41
|
+
const url = (0, exports.extractUrlFromText)(text);
|
|
42
|
+
if (!!getUrlInfo && url) {
|
|
43
|
+
try {
|
|
44
|
+
const urlInfo = await getUrlInfo(url);
|
|
45
|
+
return urlInfo;
|
|
46
|
+
}
|
|
47
|
+
catch (error) { // ignore if fails
|
|
48
|
+
logger === null || logger === void 0 ? void 0 : logger.warn({ trace: error.stack }, 'url generation failed');
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
exports.generateLinkPreviewIfRequired = generateLinkPreviewIfRequired;
|
|
53
|
+
const assertColor = async (color) => {
|
|
54
|
+
let assertedColor;
|
|
55
|
+
if (typeof color === 'number') {
|
|
56
|
+
assertedColor = color > 0 ? color : 0xffffffff + Number(color) + 1;
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
let hex = color.trim().replace('#', '');
|
|
60
|
+
if (hex.length <= 6) {
|
|
61
|
+
hex = 'FF' + hex.padStart(6, '0');
|
|
62
|
+
}
|
|
63
|
+
assertedColor = parseInt(hex, 16);
|
|
64
|
+
return assertedColor;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
const prepareWAMessageMedia = async (message, options) => {
|
|
68
|
+
const logger = options.logger;
|
|
69
|
+
let mediaType;
|
|
70
|
+
for (const key of Defaults_1.MEDIA_KEYS) {
|
|
71
|
+
if (key in message) {
|
|
72
|
+
mediaType = key;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (!mediaType) {
|
|
76
|
+
throw new boom_1.Boom('Invalid media type', { statusCode: 400 });
|
|
77
|
+
}
|
|
78
|
+
const uploadData = {
|
|
79
|
+
...message,
|
|
80
|
+
media: message[mediaType]
|
|
81
|
+
};
|
|
82
|
+
delete uploadData[mediaType];
|
|
83
|
+
// check if cacheable + generate cache key
|
|
84
|
+
const cacheableKey = typeof uploadData.media === 'object' &&
|
|
85
|
+
('url' in uploadData.media) &&
|
|
86
|
+
!!uploadData.media.url &&
|
|
87
|
+
!!options.mediaCache && (
|
|
88
|
+
// generate the key
|
|
89
|
+
mediaType + ':' + uploadData.media.url.toString());
|
|
90
|
+
if (mediaType === 'document' && !uploadData.fileName) {
|
|
91
|
+
uploadData.fileName = 'file';
|
|
92
|
+
}
|
|
93
|
+
if (!uploadData.mimetype) {
|
|
94
|
+
uploadData.mimetype = MIMETYPE_MAP[mediaType];
|
|
95
|
+
}
|
|
96
|
+
// check for cache hit
|
|
97
|
+
if (cacheableKey) {
|
|
98
|
+
const mediaBuff = options.mediaCache.get(cacheableKey);
|
|
99
|
+
if (mediaBuff) {
|
|
100
|
+
logger === null || logger === void 0 ? void 0 : logger.debug({ cacheableKey }, 'got media cache hit');
|
|
101
|
+
const obj = Types_1.WAProto.Message.decode(mediaBuff);
|
|
102
|
+
const key = `${mediaType}Message`;
|
|
103
|
+
Object.assign(obj[key], { ...uploadData, media: undefined });
|
|
104
|
+
return obj;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
const requiresDurationComputation = mediaType === 'audio' && typeof uploadData.seconds === 'undefined';
|
|
108
|
+
const requiresThumbnailComputation = (mediaType === 'image' || mediaType === 'video') &&
|
|
109
|
+
(typeof uploadData['jpegThumbnail'] === 'undefined');
|
|
110
|
+
const requiresWaveformProcessing = mediaType === 'audio' && uploadData.ptt === true;
|
|
111
|
+
const requiresAudioBackground = options.backgroundColor && mediaType === 'audio' && uploadData.ptt === true;
|
|
112
|
+
const requiresOriginalForSomeProcessing = requiresDurationComputation || requiresThumbnailComputation;
|
|
113
|
+
const { mediaKey, encWriteStream, bodyPath, fileEncSha256, fileSha256, fileLength, didSaveToTmpPath, } = await (options.newsletter ? messages_media_1.prepareStream : messages_media_1.encryptedStream)(uploadData.media, options.mediaTypeOverride || mediaType, {
|
|
114
|
+
logger,
|
|
115
|
+
saveOriginalFileIfRequired: requiresOriginalForSomeProcessing,
|
|
116
|
+
opts: options.options
|
|
117
|
+
});
|
|
118
|
+
// url safe Base64 encode the SHA256 hash of the body
|
|
119
|
+
const fileEncSha256B64 = (options.newsletter ? fileSha256 : fileEncSha256 !== null && fileEncSha256 !== void 0 ? fileEncSha256 : fileSha256).toString('base64');
|
|
120
|
+
const [{ mediaUrl, directPath, handle }] = await Promise.all([
|
|
121
|
+
(async () => {
|
|
122
|
+
const result = await options.upload(encWriteStream, { fileEncSha256B64, mediaType, timeoutMs: options.mediaUploadTimeoutMs });
|
|
123
|
+
logger === null || logger === void 0 ? void 0 : logger.debug({ mediaType, cacheableKey }, 'uploaded media');
|
|
124
|
+
return result;
|
|
125
|
+
})(),
|
|
126
|
+
(async () => {
|
|
127
|
+
try {
|
|
128
|
+
if (requiresThumbnailComputation) {
|
|
129
|
+
const { thumbnail, originalImageDimensions } = await (0, messages_media_1.generateThumbnail)(bodyPath, mediaType, options);
|
|
130
|
+
uploadData.jpegThumbnail = thumbnail;
|
|
131
|
+
if (!uploadData.width && originalImageDimensions) {
|
|
132
|
+
uploadData.width = originalImageDimensions.width;
|
|
133
|
+
uploadData.height = originalImageDimensions.height;
|
|
134
|
+
logger === null || logger === void 0 ? void 0 : logger.debug('set dimensions');
|
|
135
|
+
}
|
|
136
|
+
logger === null || logger === void 0 ? void 0 : logger.debug('generated thumbnail');
|
|
137
|
+
}
|
|
138
|
+
if (requiresDurationComputation) {
|
|
139
|
+
uploadData.seconds = await (0, messages_media_1.getAudioDuration)(bodyPath);
|
|
140
|
+
logger === null || logger === void 0 ? void 0 : logger.debug('computed audio duration');
|
|
141
|
+
}
|
|
142
|
+
if (requiresWaveformProcessing) {
|
|
143
|
+
uploadData.waveform = await (0, messages_media_1.getAudioWaveform)(bodyPath, logger);
|
|
144
|
+
logger === null || logger === void 0 ? void 0 : logger.debug('processed waveform');
|
|
145
|
+
}
|
|
146
|
+
if (requiresWaveformProcessing) {
|
|
147
|
+
uploadData.waveform = await (0, messages_media_1.getAudioWaveform)(bodyPath, logger);
|
|
148
|
+
logger === null || logger === void 0 ? void 0 : logger.debug('processed waveform');
|
|
149
|
+
}
|
|
150
|
+
if (requiresAudioBackground) {
|
|
151
|
+
uploadData.backgroundArgb = await assertColor(options.backgroundColor);
|
|
152
|
+
logger === null || logger === void 0 ? void 0 : logger.debug('computed backgroundColor audio status');
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
logger === null || logger === void 0 ? void 0 : logger.warn({ trace: error.stack }, 'failed to obtain extra info');
|
|
157
|
+
}
|
|
158
|
+
})(),
|
|
159
|
+
])
|
|
160
|
+
.finally(async () => {
|
|
161
|
+
if (!Buffer.isBuffer(encWriteStream)) {
|
|
162
|
+
encWriteStream.destroy();
|
|
163
|
+
}
|
|
164
|
+
// remove tmp files
|
|
165
|
+
if (didSaveToTmpPath && bodyPath) {
|
|
166
|
+
await fs_1.promises.unlink(bodyPath);
|
|
167
|
+
logger === null || logger === void 0 ? void 0 : logger.debug('removed tmp files');
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
const obj = Types_1.WAProto.Message.fromObject({
|
|
171
|
+
[`${mediaType}Message`]: MessageTypeProto[mediaType].fromObject({
|
|
172
|
+
url: handle ? undefined : mediaUrl,
|
|
173
|
+
directPath,
|
|
174
|
+
mediaKey: mediaKey,
|
|
175
|
+
fileEncSha256: fileEncSha256,
|
|
176
|
+
fileSha256,
|
|
177
|
+
fileLength,
|
|
178
|
+
mediaKeyTimestamp: handle ? undefined : (0, generics_1.unixTimestampSeconds)(),
|
|
179
|
+
...uploadData,
|
|
180
|
+
media: undefined
|
|
181
|
+
})
|
|
182
|
+
});
|
|
183
|
+
if (uploadData.ptv) {
|
|
184
|
+
obj.ptvMessage = obj.videoMessage;
|
|
185
|
+
delete obj.videoMessage;
|
|
186
|
+
}
|
|
187
|
+
if (cacheableKey) {
|
|
188
|
+
logger === null || logger === void 0 ? void 0 : logger.debug({ cacheableKey }, 'set cache');
|
|
189
|
+
options.mediaCache.set(cacheableKey, Types_1.WAProto.Message.encode(obj).finish());
|
|
190
|
+
}
|
|
191
|
+
return obj;
|
|
192
|
+
};
|
|
193
|
+
exports.prepareWAMessageMedia = prepareWAMessageMedia;
|
|
194
|
+
const prepareDisappearingMessageSettingContent = (ephemeralExpiration) => {
|
|
195
|
+
ephemeralExpiration = ephemeralExpiration || 0;
|
|
196
|
+
const content = {
|
|
197
|
+
ephemeralMessage: {
|
|
198
|
+
message: {
|
|
199
|
+
protocolMessage: {
|
|
200
|
+
type: Types_1.WAProto.Message.ProtocolMessage.Type.EPHEMERAL_SETTING,
|
|
201
|
+
ephemeralExpiration
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
return Types_1.WAProto.Message.fromObject(content);
|
|
207
|
+
};
|
|
208
|
+
exports.prepareDisappearingMessageSettingContent = prepareDisappearingMessageSettingContent;
|
|
209
|
+
/**
|
|
210
|
+
* Generate forwarded message content like WA does
|
|
211
|
+
* @param message the message to forward
|
|
212
|
+
* @param options.forceForward will show the message as forwarded even if it is from you
|
|
213
|
+
*/
|
|
214
|
+
const generateForwardMessageContent = (message, forceForward) => {
|
|
215
|
+
var _a;
|
|
216
|
+
let content = message.message;
|
|
217
|
+
if (!content) {
|
|
218
|
+
throw new boom_1.Boom('no content in message', { statusCode: 400 });
|
|
219
|
+
}
|
|
220
|
+
// hacky copy
|
|
221
|
+
content = (0, exports.normalizeMessageContent)(content);
|
|
222
|
+
content = WAProto_1.proto.Message.decode(WAProto_1.proto.Message.encode(content).finish());
|
|
223
|
+
let key = Object.keys(content)[0];
|
|
224
|
+
let score = ((_a = content[key].contextInfo) === null || _a === void 0 ? void 0 : _a.forwardingScore) || 0;
|
|
225
|
+
score += message.key.fromMe && !forceForward ? 0 : 1;
|
|
226
|
+
if (key === 'conversation') {
|
|
227
|
+
content.extendedTextMessage = { text: content[key] };
|
|
228
|
+
delete content.conversation;
|
|
229
|
+
key = 'extendedTextMessage';
|
|
230
|
+
}
|
|
231
|
+
if (score > 0) {
|
|
232
|
+
content[key].contextInfo = { forwardingScore: score, isForwarded: true };
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
content[key].contextInfo = {};
|
|
236
|
+
}
|
|
237
|
+
return content;
|
|
238
|
+
};
|
|
239
|
+
exports.generateForwardMessageContent = generateForwardMessageContent;
|
|
240
|
+
const generateWAMessageContent = async (message, options) => {
|
|
241
|
+
var _a;
|
|
242
|
+
var _b, _c;
|
|
243
|
+
let m = {};
|
|
244
|
+
if ('text' in message) {
|
|
245
|
+
const extContent = { text: message.text };
|
|
246
|
+
let urlInfo = message.linkPreview;
|
|
247
|
+
if (typeof urlInfo === 'undefined') {
|
|
248
|
+
urlInfo = await (0, exports.generateLinkPreviewIfRequired)(message.text, options.getUrlInfo, options.logger);
|
|
249
|
+
}
|
|
250
|
+
if (urlInfo) {
|
|
251
|
+
extContent.canonicalUrl = urlInfo['canonical-url'];
|
|
252
|
+
extContent.matchedText = urlInfo['matched-text'];
|
|
253
|
+
extContent.jpegThumbnail = urlInfo.jpegThumbnail;
|
|
254
|
+
extContent.description = urlInfo.description;
|
|
255
|
+
extContent.title = urlInfo.title;
|
|
256
|
+
extContent.previewType = 0;
|
|
257
|
+
const img = urlInfo.highQualityThumbnail;
|
|
258
|
+
if (img) {
|
|
259
|
+
extContent.thumbnailDirectPath = img.directPath;
|
|
260
|
+
extContent.mediaKey = img.mediaKey;
|
|
261
|
+
extContent.mediaKeyTimestamp = img.mediaKeyTimestamp;
|
|
262
|
+
extContent.thumbnailWidth = img.width;
|
|
263
|
+
extContent.thumbnailHeight = img.height;
|
|
264
|
+
extContent.thumbnailSha256 = img.fileSha256;
|
|
265
|
+
extContent.thumbnailEncSha256 = img.fileEncSha256;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
if (options.backgroundColor) {
|
|
269
|
+
extContent.backgroundArgb = await assertColor(options.backgroundColor);
|
|
270
|
+
}
|
|
271
|
+
if (options.font) {
|
|
272
|
+
extContent.font = options.font;
|
|
273
|
+
}
|
|
274
|
+
m.extendedTextMessage = extContent;
|
|
275
|
+
}
|
|
276
|
+
else if ('contacts' in message) {
|
|
277
|
+
const contactLen = message.contacts.contacts.length;
|
|
278
|
+
if (!contactLen) {
|
|
279
|
+
throw new boom_1.Boom('require atleast 1 contact', { statusCode: 400 });
|
|
280
|
+
}
|
|
281
|
+
if (contactLen === 1) {
|
|
282
|
+
m.contactMessage = Types_1.WAProto.Message.ContactMessage.fromObject(message.contacts.contacts[0]);
|
|
283
|
+
}
|
|
284
|
+
else {
|
|
285
|
+
m.contactsArrayMessage = Types_1.WAProto.Message.ContactsArrayMessage.fromObject(message.contacts);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
else if ('location' in message) {
|
|
289
|
+
m.locationMessage = Types_1.WAProto.Message.LocationMessage.fromObject(message.location);
|
|
290
|
+
}
|
|
291
|
+
else if ('react' in message) {
|
|
292
|
+
if (!message.react.senderTimestampMs) {
|
|
293
|
+
message.react.senderTimestampMs = Date.now();
|
|
294
|
+
}
|
|
295
|
+
m.reactionMessage = Types_1.WAProto.Message.ReactionMessage.fromObject(message.react);
|
|
296
|
+
}
|
|
297
|
+
else if ('delete' in message) {
|
|
298
|
+
m.protocolMessage = {
|
|
299
|
+
key: message.delete,
|
|
300
|
+
type: Types_1.WAProto.Message.ProtocolMessage.Type.REVOKE
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
else if ('forward' in message) {
|
|
304
|
+
m = (0, exports.generateForwardMessageContent)(message.forward, message.force);
|
|
305
|
+
}
|
|
306
|
+
else if ('disappearingMessagesInChat' in message) {
|
|
307
|
+
const exp = typeof message.disappearingMessagesInChat === 'boolean' ?
|
|
308
|
+
(message.disappearingMessagesInChat ? Defaults_1.WA_DEFAULT_EPHEMERAL : 0) :
|
|
309
|
+
message.disappearingMessagesInChat;
|
|
310
|
+
m = (0, exports.prepareDisappearingMessageSettingContent)(exp);
|
|
311
|
+
}
|
|
312
|
+
else if ('groupInvite' in message) {
|
|
313
|
+
m.groupInviteMessage = {};
|
|
314
|
+
m.groupInviteMessage.inviteCode = message.groupInvite.inviteCode;
|
|
315
|
+
m.groupInviteMessage.inviteExpiration = message.groupInvite.inviteExpiration;
|
|
316
|
+
m.groupInviteMessage.caption = message.groupInvite.text;
|
|
317
|
+
m.groupInviteMessage.groupJid = message.groupInvite.jid;
|
|
318
|
+
m.groupInviteMessage.groupName = message.groupInvite.subject;
|
|
319
|
+
//TODO: use built-in interface and get disappearing mode info etc.
|
|
320
|
+
//TODO: cache / use store!?
|
|
321
|
+
if (options.getProfilePicUrl) {
|
|
322
|
+
const pfpUrl = await options.getProfilePicUrl(message.groupInvite.jid, 'preview');
|
|
323
|
+
if (pfpUrl) {
|
|
324
|
+
const resp = await axios_1.default.get(pfpUrl, { responseType: 'arraybuffer' });
|
|
325
|
+
if (resp.status === 200) {
|
|
326
|
+
m.groupInviteMessage.jpegThumbnail = resp.data;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
else if ('pin' in message) {
|
|
332
|
+
m.pinInChatMessage = {};
|
|
333
|
+
m.messageContextInfo = {};
|
|
334
|
+
m.pinInChatMessage.key = message.pin;
|
|
335
|
+
m.pinInChatMessage.type = 1;
|
|
336
|
+
m.pinInChatMessage.senderTimestampMs = Date.now();
|
|
337
|
+
m.messageContextInfo.messageAddOnDurationInSecs = message.time || 86400;
|
|
338
|
+
}
|
|
339
|
+
else if ('unpin' in message) {
|
|
340
|
+
m.pinInChatMessage = {};
|
|
341
|
+
m.messageContextInfo = {};
|
|
342
|
+
m.pinInChatMessage.key = message.unpin;
|
|
343
|
+
m.pinInChatMessage.type = 2;
|
|
344
|
+
m.pinInChatMessage.senderTimestampMs = Date.now();
|
|
345
|
+
m.messageContextInfo.messageAddOnDurationInSecs = 0;
|
|
346
|
+
}
|
|
347
|
+
else if ('buttonReply' in message) {
|
|
348
|
+
switch (message.type) {
|
|
349
|
+
case 'template':
|
|
350
|
+
m.templateButtonReplyMessage = {
|
|
351
|
+
selectedDisplayText: message.buttonReply.displayText,
|
|
352
|
+
selectedId: message.buttonReply.id,
|
|
353
|
+
selectedIndex: message.buttonReply.index,
|
|
354
|
+
};
|
|
355
|
+
break;
|
|
356
|
+
case 'plain':
|
|
357
|
+
m.buttonsResponseMessage = {
|
|
358
|
+
selectedButtonId: message.buttonReply.id,
|
|
359
|
+
selectedDisplayText: message.buttonReply.displayText,
|
|
360
|
+
type: WAProto_1.proto.Message.ButtonsResponseMessage.Type.DISPLAY_TEXT,
|
|
361
|
+
};
|
|
362
|
+
break;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
else if ('ptv' in message && message.ptv) {
|
|
366
|
+
const { videoMessage } = await (0, exports.prepareWAMessageMedia)({ video: message.video }, options);
|
|
367
|
+
m.ptvMessage = videoMessage;
|
|
368
|
+
}
|
|
369
|
+
else if ('product' in message) {
|
|
370
|
+
const { imageMessage } = await (0, exports.prepareWAMessageMedia)({ image: message.product.productImage }, options);
|
|
371
|
+
m.productMessage = Types_1.WAProto.Message.ProductMessage.fromObject({
|
|
372
|
+
...message,
|
|
373
|
+
product: {
|
|
374
|
+
...message.product,
|
|
375
|
+
productImage: imageMessage,
|
|
376
|
+
}
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
else if ('listReply' in message) {
|
|
380
|
+
m.listResponseMessage = { ...message.listReply };
|
|
381
|
+
}
|
|
382
|
+
else if ('poll' in message) {
|
|
383
|
+
(_b = message.poll).selectableCount || (_b.selectableCount = 0);
|
|
384
|
+
(_c = message.poll).toAnnouncementGroup || (_c.toAnnouncementGroup = false);
|
|
385
|
+
if (!Array.isArray(message.poll.values)) {
|
|
386
|
+
throw new boom_1.Boom('Invalid poll values', { statusCode: 400 });
|
|
387
|
+
}
|
|
388
|
+
if (message.poll.selectableCount < 0
|
|
389
|
+
|| message.poll.selectableCount > message.poll.values.length) {
|
|
390
|
+
throw new boom_1.Boom(`poll.selectableCount in poll should be >= 0 and <= ${message.poll.values.length}`, { statusCode: 400 });
|
|
391
|
+
}
|
|
392
|
+
m.messageContextInfo = {
|
|
393
|
+
// encKey
|
|
394
|
+
messageSecret: message.poll.messageSecret || (0, crypto_1.randomBytes)(32),
|
|
395
|
+
};
|
|
396
|
+
const pollCreationMessage = {
|
|
397
|
+
name: message.poll.name,
|
|
398
|
+
selectableOptionsCount: message.poll.selectableCount,
|
|
399
|
+
options: message.poll.values.map(optionName => ({ optionName })),
|
|
400
|
+
};
|
|
401
|
+
if (message.poll.toAnnouncementGroup) {
|
|
402
|
+
// poll v2 is for community announcement groups (single select and multiple)
|
|
403
|
+
m.pollCreationMessageV2 = pollCreationMessage;
|
|
404
|
+
}
|
|
405
|
+
else {
|
|
406
|
+
if (message.poll.selectableCount > 0) {
|
|
407
|
+
//poll v3 is for single select polls
|
|
408
|
+
m.pollCreationMessageV3 = pollCreationMessage;
|
|
409
|
+
}
|
|
410
|
+
else {
|
|
411
|
+
// poll v3 for multiple choice polls
|
|
412
|
+
m.pollCreationMessage = pollCreationMessage;
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
else if ('sharePhoneNumber' in message) {
|
|
417
|
+
m.protocolMessage = {
|
|
418
|
+
type: WAProto_1.proto.Message.ProtocolMessage.Type.SHARE_PHONE_NUMBER
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
else if ('requestPhoneNumber' in message) {
|
|
422
|
+
m.requestPhoneNumberMessage = {};
|
|
423
|
+
}
|
|
424
|
+
else {
|
|
425
|
+
m = await (0, exports.prepareWAMessageMedia)(message, options);
|
|
426
|
+
}
|
|
427
|
+
if ('viewOnce' in message && !!message.viewOnce) {
|
|
428
|
+
m = { viewOnceMessage: { message: m } };
|
|
429
|
+
}
|
|
430
|
+
if ('mentions' in message && ((_a = message.mentions) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
431
|
+
const [messageType] = Object.keys(m);
|
|
432
|
+
m[messageType].contextInfo = m[messageType] || {};
|
|
433
|
+
m[messageType].contextInfo.mentionedJid = message.mentions;
|
|
434
|
+
}
|
|
435
|
+
if ('edit' in message) {
|
|
436
|
+
m = {
|
|
437
|
+
protocolMessage: {
|
|
438
|
+
key: message.edit,
|
|
439
|
+
editedMessage: m,
|
|
440
|
+
timestampMs: Date.now(),
|
|
441
|
+
type: Types_1.WAProto.Message.ProtocolMessage.Type.MESSAGE_EDIT
|
|
442
|
+
}
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
if ('contextInfo' in message && !!message.contextInfo) {
|
|
446
|
+
const [messageType] = Object.keys(m);
|
|
447
|
+
m[messageType] = m[messageType] || {};
|
|
448
|
+
m[messageType].contextInfo = message.contextInfo;
|
|
449
|
+
}
|
|
450
|
+
return Types_1.WAProto.Message.fromObject(m);
|
|
451
|
+
};
|
|
452
|
+
exports.generateWAMessageContent = generateWAMessageContent;
|
|
453
|
+
const generateWAMessageFromContent = (jid, message, options) => {
|
|
454
|
+
// set timestamp to now
|
|
455
|
+
// if not specified
|
|
456
|
+
if (!options.timestamp) {
|
|
457
|
+
options.timestamp = new Date();
|
|
458
|
+
}
|
|
459
|
+
const innerMessage = (0, exports.normalizeMessageContent)(message);
|
|
460
|
+
const key = (0, exports.getContentType)(innerMessage);
|
|
461
|
+
const timestamp = (0, generics_1.unixTimestampSeconds)(options.timestamp);
|
|
462
|
+
const { quoted, userJid } = options;
|
|
463
|
+
// only set quoted if isn't a newsletter message
|
|
464
|
+
if (quoted && !(0, WABinary_1.isJidNewsletter)(jid)) {
|
|
465
|
+
const participant = quoted.key.fromMe ? userJid : (quoted.participant || quoted.key.participant || quoted.key.remoteJid);
|
|
466
|
+
let quotedMsg = (0, exports.normalizeMessageContent)(quoted.message);
|
|
467
|
+
const msgType = (0, exports.getContentType)(quotedMsg);
|
|
468
|
+
// strip any redundant properties
|
|
469
|
+
quotedMsg = WAProto_1.proto.Message.fromObject({ [msgType]: quotedMsg[msgType] });
|
|
470
|
+
const quotedContent = quotedMsg[msgType];
|
|
471
|
+
if (typeof quotedContent === 'object' && quotedContent && 'contextInfo' in quotedContent) {
|
|
472
|
+
delete quotedContent.contextInfo;
|
|
473
|
+
}
|
|
474
|
+
const contextInfo = innerMessage[key].contextInfo || {};
|
|
475
|
+
contextInfo.participant = (0, WABinary_1.jidNormalizedUser)(participant);
|
|
476
|
+
contextInfo.stanzaId = quoted.key.id;
|
|
477
|
+
contextInfo.quotedMessage = quotedMsg;
|
|
478
|
+
// if a participant is quoted, then it must be a group
|
|
479
|
+
// hence, remoteJid of group must also be entered
|
|
480
|
+
if (jid !== quoted.key.remoteJid) {
|
|
481
|
+
contextInfo.remoteJid = quoted.key.remoteJid;
|
|
482
|
+
}
|
|
483
|
+
innerMessage[key].contextInfo = contextInfo;
|
|
484
|
+
}
|
|
485
|
+
if (
|
|
486
|
+
// if we want to send a disappearing message
|
|
487
|
+
!!(options === null || options === void 0 ? void 0 : options.ephemeralExpiration) &&
|
|
488
|
+
// and it's not a protocol message -- delete, toggle disappear message
|
|
489
|
+
key !== 'protocolMessage' &&
|
|
490
|
+
// already not converted to disappearing message
|
|
491
|
+
key !== 'ephemeralMessage' &&
|
|
492
|
+
// newsletter not accept disappearing messages
|
|
493
|
+
!(0, WABinary_1.isJidNewsletter)(jid)) {
|
|
494
|
+
innerMessage[key].contextInfo = {
|
|
495
|
+
...(innerMessage[key].contextInfo || {}),
|
|
496
|
+
expiration: options.ephemeralExpiration || Defaults_1.WA_DEFAULT_EPHEMERAL,
|
|
497
|
+
//ephemeralSettingTimestamp: options.ephemeralOptions.eph_setting_ts?.toString()
|
|
498
|
+
};
|
|
499
|
+
}
|
|
500
|
+
message = Types_1.WAProto.Message.fromObject(message);
|
|
501
|
+
const messageJSON = {
|
|
502
|
+
key: {
|
|
503
|
+
remoteJid: jid,
|
|
504
|
+
fromMe: true,
|
|
505
|
+
id: (options === null || options === void 0 ? void 0 : options.messageId) || (0, generics_1.generateMessageID)(),
|
|
506
|
+
},
|
|
507
|
+
message: message,
|
|
508
|
+
messageTimestamp: timestamp,
|
|
509
|
+
messageStubParameters: [],
|
|
510
|
+
participant: (0, WABinary_1.isJidGroup)(jid) || (0, WABinary_1.isJidStatusBroadcast)(jid) ? userJid : undefined,
|
|
511
|
+
status: Types_1.WAMessageStatus.PENDING
|
|
512
|
+
};
|
|
513
|
+
return Types_1.WAProto.WebMessageInfo.fromObject(messageJSON);
|
|
514
|
+
};
|
|
515
|
+
exports.generateWAMessageFromContent = generateWAMessageFromContent;
|
|
516
|
+
const generateWAMessage = async (jid, content, options) => {
|
|
517
|
+
var _a;
|
|
518
|
+
// ensure msg ID is with every log
|
|
519
|
+
options.logger = (_a = options === null || options === void 0 ? void 0 : options.logger) === null || _a === void 0 ? void 0 : _a.child({ msgId: options.messageId });
|
|
520
|
+
return (0, exports.generateWAMessageFromContent)(jid, await (0, exports.generateWAMessageContent)(content, { newsletter: (0, WABinary_1.isJidNewsletter)(jid), ...options }), options);
|
|
521
|
+
};
|
|
522
|
+
exports.generateWAMessage = generateWAMessage;
|
|
523
|
+
/** Get the key to access the true type of content */
|
|
524
|
+
const getContentType = (content) => {
|
|
525
|
+
if (content) {
|
|
526
|
+
const keys = Object.keys(content);
|
|
527
|
+
const key = keys.find(k => (k === 'conversation' || k.includes('Message')) && k !== 'senderKeyDistributionMessage');
|
|
528
|
+
return key;
|
|
529
|
+
}
|
|
530
|
+
};
|
|
531
|
+
exports.getContentType = getContentType;
|
|
532
|
+
/**
|
|
533
|
+
* Normalizes ephemeral, view once messages to regular message content
|
|
534
|
+
* Eg. image messages in ephemeral messages, in view once messages etc.
|
|
535
|
+
* @param content
|
|
536
|
+
* @returns
|
|
537
|
+
*/
|
|
538
|
+
const normalizeMessageContent = (content) => {
|
|
539
|
+
if (!content) {
|
|
540
|
+
return undefined;
|
|
541
|
+
}
|
|
542
|
+
// set max iterations to prevent an infinite loop
|
|
543
|
+
for (let i = 0; i < 5; i++) {
|
|
544
|
+
const inner = getFutureProofMessage(content);
|
|
545
|
+
if (!inner) {
|
|
546
|
+
break;
|
|
547
|
+
}
|
|
548
|
+
content = inner.message;
|
|
549
|
+
}
|
|
550
|
+
return content;
|
|
551
|
+
function getFutureProofMessage(message) {
|
|
552
|
+
return ((message === null || message === void 0 ? void 0 : message.ephemeralMessage)
|
|
553
|
+
|| (message === null || message === void 0 ? void 0 : message.viewOnceMessage)
|
|
554
|
+
|| (message === null || message === void 0 ? void 0 : message.documentWithCaptionMessage)
|
|
555
|
+
|| (message === null || message === void 0 ? void 0 : message.viewOnceMessageV2)
|
|
556
|
+
|| (message === null || message === void 0 ? void 0 : message.viewOnceMessageV2Extension)
|
|
557
|
+
|| (message === null || message === void 0 ? void 0 : message.editedMessage));
|
|
558
|
+
}
|
|
559
|
+
};
|
|
560
|
+
exports.normalizeMessageContent = normalizeMessageContent;
|
|
561
|
+
/**
|
|
562
|
+
* Extract the true message content from a message
|
|
563
|
+
* Eg. extracts the inner message from a disappearing message/view once message
|
|
564
|
+
*/
|
|
565
|
+
const extractMessageContent = (content) => {
|
|
566
|
+
var _a, _b, _c, _d, _e, _f;
|
|
567
|
+
const extractFromTemplateMessage = (msg) => {
|
|
568
|
+
if (msg.imageMessage) {
|
|
569
|
+
return { imageMessage: msg.imageMessage };
|
|
570
|
+
}
|
|
571
|
+
else if (msg.documentMessage) {
|
|
572
|
+
return { documentMessage: msg.documentMessage };
|
|
573
|
+
}
|
|
574
|
+
else if (msg.videoMessage) {
|
|
575
|
+
return { videoMessage: msg.videoMessage };
|
|
576
|
+
}
|
|
577
|
+
else if (msg.locationMessage) {
|
|
578
|
+
return { locationMessage: msg.locationMessage };
|
|
579
|
+
}
|
|
580
|
+
else {
|
|
581
|
+
return {
|
|
582
|
+
conversation: 'contentText' in msg
|
|
583
|
+
? msg.contentText
|
|
584
|
+
: ('hydratedContentText' in msg ? msg.hydratedContentText : '')
|
|
585
|
+
};
|
|
586
|
+
}
|
|
587
|
+
};
|
|
588
|
+
content = (0, exports.normalizeMessageContent)(content);
|
|
589
|
+
if (content === null || content === void 0 ? void 0 : content.buttonsMessage) {
|
|
590
|
+
return extractFromTemplateMessage(content.buttonsMessage);
|
|
591
|
+
}
|
|
592
|
+
if ((_a = content === null || content === void 0 ? void 0 : content.templateMessage) === null || _a === void 0 ? void 0 : _a.hydratedFourRowTemplate) {
|
|
593
|
+
return extractFromTemplateMessage((_b = content === null || content === void 0 ? void 0 : content.templateMessage) === null || _b === void 0 ? void 0 : _b.hydratedFourRowTemplate);
|
|
594
|
+
}
|
|
595
|
+
if ((_c = content === null || content === void 0 ? void 0 : content.templateMessage) === null || _c === void 0 ? void 0 : _c.hydratedTemplate) {
|
|
596
|
+
return extractFromTemplateMessage((_d = content === null || content === void 0 ? void 0 : content.templateMessage) === null || _d === void 0 ? void 0 : _d.hydratedTemplate);
|
|
597
|
+
}
|
|
598
|
+
if ((_e = content === null || content === void 0 ? void 0 : content.templateMessage) === null || _e === void 0 ? void 0 : _e.fourRowTemplate) {
|
|
599
|
+
return extractFromTemplateMessage((_f = content === null || content === void 0 ? void 0 : content.templateMessage) === null || _f === void 0 ? void 0 : _f.fourRowTemplate);
|
|
600
|
+
}
|
|
601
|
+
return content;
|
|
602
|
+
};
|
|
603
|
+
exports.extractMessageContent = extractMessageContent;
|
|
604
|
+
/**
|
|
605
|
+
* Returns the device predicted by message ID
|
|
606
|
+
*/
|
|
607
|
+
const getDevice = (id) => /^3A.{18}$/.test(id) ? 'ios' : /^3E.{20}$/.test(id) ? 'web' : /^(.{21}|.{32})$/.test(id) ? 'android' : /^.{18}$/.test(id) ? 'desktop' : 'unknown';
|
|
608
|
+
exports.getDevice = getDevice;
|
|
609
|
+
/** Upserts a receipt in the message */
|
|
610
|
+
const updateMessageWithReceipt = (msg, receipt) => {
|
|
611
|
+
msg.userReceipt = msg.userReceipt || [];
|
|
612
|
+
const recp = msg.userReceipt.find(m => m.userJid === receipt.userJid);
|
|
613
|
+
if (recp) {
|
|
614
|
+
Object.assign(recp, receipt);
|
|
615
|
+
}
|
|
616
|
+
else {
|
|
617
|
+
msg.userReceipt.push(receipt);
|
|
618
|
+
}
|
|
619
|
+
};
|
|
620
|
+
exports.updateMessageWithReceipt = updateMessageWithReceipt;
|
|
621
|
+
/** Update the message with a new reaction */
|
|
622
|
+
const updateMessageWithReaction = (msg, reaction) => {
|
|
623
|
+
const authorID = (0, generics_1.getKeyAuthor)(reaction.key);
|
|
624
|
+
const reactions = (msg.reactions || [])
|
|
625
|
+
.filter(r => (0, generics_1.getKeyAuthor)(r.key) !== authorID);
|
|
626
|
+
if (reaction.text) {
|
|
627
|
+
reactions.push(reaction);
|
|
628
|
+
}
|
|
629
|
+
msg.reactions = reactions;
|
|
630
|
+
};
|
|
631
|
+
exports.updateMessageWithReaction = updateMessageWithReaction;
|
|
632
|
+
/** Update the message with a new poll update */
|
|
633
|
+
const updateMessageWithPollUpdate = (msg, update) => {
|
|
634
|
+
var _a, _b;
|
|
635
|
+
const authorID = (0, generics_1.getKeyAuthor)(update.pollUpdateMessageKey);
|
|
636
|
+
const reactions = (msg.pollUpdates || [])
|
|
637
|
+
.filter(r => (0, generics_1.getKeyAuthor)(r.pollUpdateMessageKey) !== authorID);
|
|
638
|
+
if ((_b = (_a = update.vote) === null || _a === void 0 ? void 0 : _a.selectedOptions) === null || _b === void 0 ? void 0 : _b.length) {
|
|
639
|
+
reactions.push(update);
|
|
640
|
+
}
|
|
641
|
+
msg.pollUpdates = reactions;
|
|
642
|
+
};
|
|
643
|
+
exports.updateMessageWithPollUpdate = updateMessageWithPollUpdate;
|
|
644
|
+
/**
|
|
645
|
+
* Aggregates all poll updates in a poll.
|
|
646
|
+
* @param msg the poll creation message
|
|
647
|
+
* @param meId your jid
|
|
648
|
+
* @returns A list of options & their voters
|
|
649
|
+
*/
|
|
650
|
+
function getAggregateVotesInPollMessage({ message, pollUpdates }, meId) {
|
|
651
|
+
var _a, _b, _c;
|
|
652
|
+
const opts = ((_a = message === null || message === void 0 ? void 0 : message.pollCreationMessage) === null || _a === void 0 ? void 0 : _a.options) || ((_b = message === null || message === void 0 ? void 0 : message.pollCreationMessageV2) === null || _b === void 0 ? void 0 : _b.options) || ((_c = message === null || message === void 0 ? void 0 : message.pollCreationMessageV3) === null || _c === void 0 ? void 0 : _c.options) || [];
|
|
653
|
+
const voteHashMap = opts.reduce((acc, opt) => {
|
|
654
|
+
const hash = (0, crypto_2.sha256)(Buffer.from(opt.optionName || '')).toString();
|
|
655
|
+
acc[hash] = {
|
|
656
|
+
name: opt.optionName || '',
|
|
657
|
+
voters: []
|
|
658
|
+
};
|
|
659
|
+
return acc;
|
|
660
|
+
}, {});
|
|
661
|
+
for (const update of pollUpdates || []) {
|
|
662
|
+
const { vote } = update;
|
|
663
|
+
if (!vote) {
|
|
664
|
+
continue;
|
|
665
|
+
}
|
|
666
|
+
for (const option of vote.selectedOptions || []) {
|
|
667
|
+
const hash = option.toString();
|
|
668
|
+
let data = voteHashMap[hash];
|
|
669
|
+
if (!data) {
|
|
670
|
+
voteHashMap[hash] = {
|
|
671
|
+
name: 'Unknown',
|
|
672
|
+
voters: []
|
|
673
|
+
};
|
|
674
|
+
data = voteHashMap[hash];
|
|
675
|
+
}
|
|
676
|
+
voteHashMap[hash].voters.push((0, generics_1.getKeyAuthor)(update.pollUpdateMessageKey, meId));
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
return Object.values(voteHashMap);
|
|
680
|
+
}
|
|
681
|
+
exports.getAggregateVotesInPollMessage = getAggregateVotesInPollMessage;
|
|
682
|
+
/** Given a list of message keys, aggregates them by chat & sender. Useful for sending read receipts in bulk */
|
|
683
|
+
const aggregateMessageKeysNotFromMe = (keys) => {
|
|
684
|
+
const keyMap = {};
|
|
685
|
+
for (const { remoteJid, id, participant, fromMe } of keys) {
|
|
686
|
+
if (!fromMe) {
|
|
687
|
+
const uqKey = `${remoteJid}:${participant || ''}`;
|
|
688
|
+
if (!keyMap[uqKey]) {
|
|
689
|
+
keyMap[uqKey] = {
|
|
690
|
+
jid: remoteJid,
|
|
691
|
+
participant: participant,
|
|
692
|
+
messageIds: []
|
|
693
|
+
};
|
|
694
|
+
}
|
|
695
|
+
keyMap[uqKey].messageIds.push(id);
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
return Object.values(keyMap);
|
|
699
|
+
};
|
|
700
|
+
exports.aggregateMessageKeysNotFromMe = aggregateMessageKeysNotFromMe;
|
|
701
|
+
const REUPLOAD_REQUIRED_STATUS = [410, 404];
|
|
702
|
+
/**
|
|
703
|
+
* Downloads the given message. Throws an error if it's not a media message
|
|
704
|
+
*/
|
|
705
|
+
const downloadMediaMessage = async (message, type, options, ctx) => {
|
|
706
|
+
const result = await downloadMsg()
|
|
707
|
+
.catch(async (error) => {
|
|
708
|
+
var _a;
|
|
709
|
+
if (ctx) {
|
|
710
|
+
if (axios_1.default.isAxiosError(error)) {
|
|
711
|
+
// check if the message requires a reupload
|
|
712
|
+
if (REUPLOAD_REQUIRED_STATUS.includes((_a = error.response) === null || _a === void 0 ? void 0 : _a.status)) {
|
|
713
|
+
ctx.logger.info({ key: message.key }, 'sending reupload media request...');
|
|
714
|
+
// request reupload
|
|
715
|
+
message = await ctx.reuploadRequest(message);
|
|
716
|
+
const result = await downloadMsg();
|
|
717
|
+
return result;
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
throw error;
|
|
722
|
+
});
|
|
723
|
+
return result;
|
|
724
|
+
async function downloadMsg() {
|
|
725
|
+
const mContent = (0, exports.extractMessageContent)(message.message);
|
|
726
|
+
if (!mContent) {
|
|
727
|
+
throw new boom_1.Boom('No message present', { statusCode: 400, data: message });
|
|
728
|
+
}
|
|
729
|
+
const contentType = (0, exports.getContentType)(mContent);
|
|
730
|
+
let mediaType = contentType === null || contentType === void 0 ? void 0 : contentType.replace('Message', '');
|
|
731
|
+
const media = mContent[contentType];
|
|
732
|
+
if (!media || typeof media !== 'object' || (!('url' in media) && !('thumbnailDirectPath' in media))) {
|
|
733
|
+
throw new boom_1.Boom(`"${contentType}" message is not a media message`);
|
|
734
|
+
}
|
|
735
|
+
let download;
|
|
736
|
+
if ('thumbnailDirectPath' in media && !('url' in media)) {
|
|
737
|
+
download = {
|
|
738
|
+
directPath: media.thumbnailDirectPath,
|
|
739
|
+
mediaKey: media.mediaKey
|
|
740
|
+
};
|
|
741
|
+
mediaType = 'thumbnail-link';
|
|
742
|
+
}
|
|
743
|
+
else {
|
|
744
|
+
download = media;
|
|
745
|
+
}
|
|
746
|
+
const stream = await (0, messages_media_1.downloadContentFromMessage)(download, mediaType, options);
|
|
747
|
+
if (type === 'buffer') {
|
|
748
|
+
const bufferArray = [];
|
|
749
|
+
for await (const chunk of stream) {
|
|
750
|
+
bufferArray.push(chunk);
|
|
751
|
+
}
|
|
752
|
+
return Buffer.concat(bufferArray);
|
|
753
|
+
}
|
|
754
|
+
return stream;
|
|
755
|
+
}
|
|
756
|
+
};
|
|
757
|
+
exports.downloadMediaMessage = downloadMediaMessage;
|
|
758
|
+
/** Checks whether the given message is a media message; if it is returns the inner content */
|
|
759
|
+
const assertMediaContent = (content) => {
|
|
760
|
+
content = (0, exports.extractMessageContent)(content);
|
|
761
|
+
const mediaContent = (content === null || content === void 0 ? void 0 : content.documentMessage)
|
|
762
|
+
|| (content === null || content === void 0 ? void 0 : content.imageMessage)
|
|
763
|
+
|| (content === null || content === void 0 ? void 0 : content.videoMessage)
|
|
764
|
+
|| (content === null || content === void 0 ? void 0 : content.audioMessage)
|
|
765
|
+
|| (content === null || content === void 0 ? void 0 : content.stickerMessage);
|
|
766
|
+
if (!mediaContent) {
|
|
767
|
+
throw new boom_1.Boom('given message is not a media message', { statusCode: 400, data: content });
|
|
768
|
+
}
|
|
769
|
+
return mediaContent;
|
|
770
|
+
};
|
|
771
|
+
exports.assertMediaContent = assertMediaContent;
|