Skip to content

Commit

Permalink
feat(baileys): added more methods
Browse files Browse the repository at this point in the history
feat(baileys): added more methods
  • Loading branch information
leifermendez committed Dec 20, 2022
2 parents 37fe323 + 16e5d4b commit 1b23b83
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 3 deletions.
92 changes: 92 additions & 0 deletions packages/provider/src/baileys/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { ProviderClass } = require('@bot-whatsapp/bot')
const { Sticker } = require('wa-sticker-formatter')
const pino = require('pino')
const mime = require('mime-types')
const { existsSync, createWriteStream } = require('fs')
Expand Down Expand Up @@ -214,6 +215,97 @@ class BaileysProvider extends ProviderClass {
return this.sendMedia(number, options.media, message)
return this.sendText(number, message)
}

/**
* @param {string} remoteJid
* @param {string} latitude
* @param {string} longitude
* @param {any} messages
* @example await sendLocation("xxxxxxxxxxx@c.us" || "xxxxxxxxxxxxxxxxxx@g.us", "xx.xxxx", "xx.xxxx", messages)
*/

sendLocation = async (remoteJid, latitude, longitude, messages = null) => {
await this.vendor.sendMessage(
remoteJid,
{
location: {
degreesLatitude: latitude,
degreesLongitude: longitude,
},
},
{ quoted: messages }
)

return { status: 'success' }
}

/**
* @param {string} remoteJid
* @param {string} contactNumber
* @param {string} displayName
* @param {any} messages - optional
* @example await sendContact("xxxxxxxxxxx@c.us" || "xxxxxxxxxxxxxxxxxx@g.us", "+xxxxxxxxxxx", "Robin Smith", messages)
*/

sendContact = async (
remoteJid,
contactNumber,
displayName,
messages = null
) => {
const cleanContactNumber = contactNumber.replaceAll(' ', '')
const waid = cleanContactNumber.replace('+', '')

const vcard =
'BEGIN:VCARD\n' +
'VERSION:3.0\n' +
`FN:${displayName}\n` +
'ORG:Ashoka Uni;\n' +
`TEL;type=CELL;type=VOICE;waid=${waid}:${cleanContactNumber}\n` +
'END:VCARD'

await this.client.sendMessage(
remoteJid,
{
contacts: {
displayName: 'XD',
contacts: [{ vcard }],
},
},
{ quoted: messages }
)

return { status: 'success' }
}

/**
* @param {string} remoteJid
* @param {string} WAPresence
* @example await sendPresenceUpdate("xxxxxxxxxxx@c.us" || "xxxxxxxxxxxxxxxxxx@g.us", "recording")
*/
sendPresenceUpdate = async (remoteJid, WAPresence) => {
await this.client.sendPresenceUpdate(WAPresence, remoteJid)
}

/**
* @param {string} remoteJid
* @param {string} url
* @param {object} stickerOptions
* @param {any} messages - optional
* @example await sendSticker("xxxxxxxxxxx@c.us" || "xxxxxxxxxxxxxxxxxx@g.us", "https://dn/image.png" || "https://dn/image.gif" || "https://dn/image.mp4", {pack: 'User', author: 'Me'} messages)
*/

sendSticker = async (remoteJid, url, stickerOptions, messages = null) => {
const sticker = new Sticker(url, {
...stickerOptions,
quality: 50,
type: 'crop',
})

const buffer = await sticker.toMessage()

await this.client.sendMessage(remoteJid, buffer, { quoted: messages })
}
}

module.exports = BaileysProvider
3 changes: 2 additions & 1 deletion starters/apps/base-bailey-memory/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"@bot-whatsapp/database": "latest",
"@bot-whatsapp/provider": "latest",
"@adiwajshing/baileys": "^4.4.0",
"mime-types": "^2.1.35"
"mime-types": "^2.1.35",
"wa-sticker-formatter": "^4.3.2"
},
"author": "",
"license": "ISC"
Expand Down
3 changes: 2 additions & 1 deletion starters/apps/base-bailey-mongo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"@bot-whatsapp/provider": "latest",
"@adiwajshing/baileys": "^4.4.0",
"mime-types": "^2.1.35",
"mongodb": "^4.12.1"
"mongodb": "^4.12.1",
"wa-sticker-formatter": "^4.3.2"
},
"author": "",
"license": "ISC"
Expand Down
3 changes: 2 additions & 1 deletion starters/apps/base-bailey-mysql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"@bot-whatsapp/provider": "latest",
"@adiwajshing/baileys": "^4.4.0",
"mime-types": "^2.1.35",
"mysql2": "^2.3.3"
"mysql2": "^2.3.3",
"wa-sticker-formatter": "^4.3.2"
},
"author": "",
"license": "ISC"
Expand Down

0 comments on commit 1b23b83

Please sign in to comment.