Skip to content

Commit

Permalink
Merge pull request ookamiiixd#40 from emregeldegul/master
Browse files Browse the repository at this point in the history
add group metadata endpoint
  • Loading branch information
ookamiiixd authored May 12, 2022
2 parents 58f0deb + a158be4 commit 3ff52a8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
15 changes: 13 additions & 2 deletions controllers/groupsController.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
import { getSession, getChatList, isExists, sendMessage, formatGroup } from './../whatsapp.js'
import { getSession, getChatList, isExists, sendMessage, formatGroup, getGroupMeta } from './../whatsapp.js'
import response from './../response.js'

const getList = (req, res) => {
return response(res, 200, true, '', getChatList(res.locals.sessionId, true))
}

const getGroupMetaData = async (req, res) => {
const session = getSession(res.locals.sessionId)
const jid = req.params.jid
let data


data = await getGroupMeta(session, jid)

response(res, 200, true, '', data)
}

const send = async (req, res) => {
const session = getSession(res.locals.sessionId)
const receiver = formatGroup(req.body.receiver)
Expand All @@ -25,4 +36,4 @@ const send = async (req, res) => {
}
}

export { getList, send }
export { getList, send, getGroupMetaData }
3 changes: 3 additions & 0 deletions routes/groupsRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ const router = Router()

router.get('/', query('id').notEmpty(), requestValidator, sessionValidator, controller.getList)

router.get('/meta/:jid', query('id').notEmpty(), requestValidator, sessionValidator, controller.getGroupMetaData)

router.get('/:jid', query('id').notEmpty(), requestValidator, sessionValidator, getMessages)


router.post(
'/send',
query('id').notEmpty(),
Expand Down
8 changes: 8 additions & 0 deletions whatsapp.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,13 @@ const getChatList = (sessionId, isGroup = false) => {
})
}

const getGroupMeta = async (session, jid) => {
let data
data = await session.groupMetadata(jid)

return data
}

/**
* @param {import('@adiwajshing/baileys').AnyWASocket} session
*/
Expand Down Expand Up @@ -287,4 +294,5 @@ export {
formatGroup,
cleanup,
init,
getGroupMeta,
}

0 comments on commit 3ff52a8

Please sign in to comment.