refactor: document endpoints

This commit is contained in:
Anton Voylenko 2024-12-07 01:02:50 +02:00
commit 8263ffb942
9 changed files with 1696 additions and 1022 deletions

View file

@ -16,19 +16,6 @@ const { sendErrorResponse } = require('../utils')
const getClassInfo = async (req, res) => { const getClassInfo = async (req, res) => {
/* /*
#swagger.summary = 'Get the chat' #swagger.summary = 'Get the chat'
#swagger.requestBody = {
required: true,
schema: {
type: 'object',
properties: {
chatId: {
type: 'string',
description: 'Unique WhatsApp identifier for the given Chat (either group or personal)',
example: '6281288888888@c.us'
},
}
},
}
*/ */
try { try {
const { chatId } = req.body const { chatId } = req.body
@ -40,15 +27,6 @@ const getClassInfo = async (req, res) => {
} }
res.json({ success: true, chat }) res.json({ success: true, chat })
} catch (error) { } catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
} }
@ -68,19 +46,6 @@ const getClassInfo = async (req, res) => {
const clearMessages = async (req, res) => { const clearMessages = async (req, res) => {
/* /*
#swagger.summary = 'Clear all messages from the chat' #swagger.summary = 'Clear all messages from the chat'
#swagger.requestBody = {
required: true,
schema: {
type: 'object',
properties: {
chatId: {
type: 'string',
description: 'Unique WhatsApp identifier for the given Chat (either group or personal)',
example: '6281288888888@c.us'
},
}
},
}
*/ */
try { try {
const { chatId } = req.body const { chatId } = req.body
@ -93,15 +58,6 @@ const clearMessages = async (req, res) => {
const result = await chat.clearMessages() const result = await chat.clearMessages()
res.json({ success: true, result }) res.json({ success: true, result })
} catch (error) { } catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
} }
@ -121,19 +77,6 @@ const clearMessages = async (req, res) => {
const clearState = async (req, res) => { const clearState = async (req, res) => {
/* /*
#swagger.summary = 'Stop typing or recording in chat immediately' #swagger.summary = 'Stop typing or recording in chat immediately'
#swagger.requestBody = {
required: true,
schema: {
type: 'object',
properties: {
chatId: {
type: 'string',
description: 'Unique WhatsApp identifier for the given Chat (either group or personal)',
example: '6281288888888@c.us'
},
}
},
}
*/ */
try { try {
const { chatId } = req.body const { chatId } = req.body
@ -146,15 +89,6 @@ const clearState = async (req, res) => {
const result = await chat.clearState() const result = await chat.clearState()
res.json({ success: true, result }) res.json({ success: true, result })
} catch (error) { } catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
} }
@ -175,19 +109,6 @@ const clearState = async (req, res) => {
const deleteChat = async (req, res) => { const deleteChat = async (req, res) => {
/* /*
#swagger.summary = 'Delete the chat' #swagger.summary = 'Delete the chat'
#swagger.requestBody = {
required: true,
schema: {
type: 'object',
properties: {
chatId: {
type: 'string',
description: 'Unique WhatsApp identifier for the given Chat (either group or personal)',
example: '6281288888888@c.us'
},
}
},
}
*/ */
try { try {
const { chatId } = req.body const { chatId } = req.body
@ -200,15 +121,6 @@ const deleteChat = async (req, res) => {
const result = await chat.delete() const result = await chat.delete()
res.json({ success: true, result }) res.json({ success: true, result })
} catch (error) { } catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
} }
@ -264,15 +176,6 @@ const fetchMessages = async (req, res) => {
const messages = Object.keys(searchOptions).length ? await chat.fetchMessages(searchOptions) : await chat.fetchMessages() const messages = Object.keys(searchOptions).length ? await chat.fetchMessages(searchOptions) : await chat.fetchMessages()
res.json({ success: true, messages }) res.json({ success: true, messages })
} catch (error) { } catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
} }
@ -291,19 +194,6 @@ const fetchMessages = async (req, res) => {
const getContact = async (req, res) => { const getContact = async (req, res) => {
/* /*
#swagger.summary = 'Get the contact' #swagger.summary = 'Get the contact'
#swagger.requestBody = {
required: true,
schema: {
type: 'object',
properties: {
chatId: {
type: 'string',
description: 'Unique WhatsApp identifier for the given Chat (either group or personal)',
example: '6281288888888@c.us'
}
}
}
}
*/ */
try { try {
const { chatId } = req.body const { chatId } = req.body
@ -316,15 +206,6 @@ const getContact = async (req, res) => {
const contact = await chat.getContact() const contact = await chat.getContact()
res.json({ success: true, contact }) res.json({ success: true, contact })
} catch (error) { } catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
} }
@ -345,19 +226,6 @@ const sendStateRecording = async (req, res) => {
/* /*
#swagger.summary = 'Simulate recording audio' #swagger.summary = 'Simulate recording audio'
#swagger.description = 'Simulate recording audio in chat. This will last for 25 seconds' #swagger.description = 'Simulate recording audio in chat. This will last for 25 seconds'
#swagger.requestBody = {
required: true,
schema: {
type: 'object',
properties: {
chatId: {
type: 'string',
description: 'Unique WhatsApp identifier for the given Chat (either group or personal)',
example: '6281288888888@c.us'
}
}
}
}
*/ */
try { try {
const { chatId } = req.body const { chatId } = req.body
@ -370,15 +238,6 @@ const sendStateRecording = async (req, res) => {
const result = await chat.sendStateRecording() const result = await chat.sendStateRecording()
res.json({ success: true, result }) res.json({ success: true, result })
} catch (error) { } catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
} }
@ -399,19 +258,6 @@ const sendStateTyping = async (req, res) => {
/* /*
#swagger.summary = 'Simulate typing in chat' #swagger.summary = 'Simulate typing in chat'
#swagger.description = 'Simulate typing in chat. This will last for 25 seconds.' #swagger.description = 'Simulate typing in chat. This will last for 25 seconds.'
#swagger.requestBody = {
required: true,
schema: {
type: 'object',
properties: {
chatId: {
type: 'string',
description: 'Unique WhatsApp identifier for the given Chat (either group or personal)',
example: '6281288888888@c.us'
}
}
}
}
*/ */
try { try {
const { chatId } = req.body const { chatId } = req.body
@ -424,15 +270,6 @@ const sendStateTyping = async (req, res) => {
const result = await chat.sendStateTyping() const result = await chat.sendStateTyping()
res.json({ success: true, result }) res.json({ success: true, result })
} catch (error) { } catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
} }
@ -452,19 +289,6 @@ const sendStateTyping = async (req, res) => {
const sendSeen = async (req, res) => { const sendSeen = async (req, res) => {
/* /*
#swagger.summary = 'Set the message as seen' #swagger.summary = 'Set the message as seen'
#swagger.requestBody = {
required: true,
schema: {
type: 'object',
properties: {
chatId: {
type: 'string',
description: 'Unique WhatsApp identifier for the given Chat (either group or personal)',
example: '6281288888888@c.us'
}
}
}
}
*/ */
try { try {
const { chatId } = req.body const { chatId } = req.body
@ -477,15 +301,6 @@ const sendSeen = async (req, res) => {
const result = await chat.sendSeen() const result = await chat.sendSeen()
res.json({ success: true, result }) res.json({ success: true, result })
} catch (error) { } catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
} }
@ -505,19 +320,6 @@ const sendSeen = async (req, res) => {
const markUnread = async (req, res) => { const markUnread = async (req, res) => {
/* /*
#swagger.summary = 'Mark this chat as unread' #swagger.summary = 'Mark this chat as unread'
#swagger.requestBody = {
required: true,
schema: {
type: 'object',
properties: {
chatId: {
type: 'string',
description: 'Unique WhatsApp identifier for the given Chat (either group or personal)',
example: '6281288888888@c.us'
}
}
}
}
*/ */
try { try {
const { chatId } = req.body const { chatId } = req.body
@ -530,15 +332,6 @@ const markUnread = async (req, res) => {
const result = await chat.markUnread() const result = await chat.markUnread()
res.json({ success: true, result }) res.json({ success: true, result })
} catch (error) { } catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
} }
@ -558,19 +351,6 @@ const markUnread = async (req, res) => {
const syncHistory = async (req, res) => { const syncHistory = async (req, res) => {
/* /*
#swagger.summary = 'Sync chat history' #swagger.summary = 'Sync chat history'
#swagger.requestBody = {
required: true,
schema: {
type: 'object',
properties: {
chatId: {
type: 'string',
description: 'Unique WhatsApp identifier for the given Chat (either group or personal)',
example: '6281288888888@c.us'
}
}
}
}
*/ */
try { try {
const { chatId } = req.body const { chatId } = req.body
@ -583,15 +363,6 @@ const syncHistory = async (req, res) => {
const result = await chat.syncHistory() const result = await chat.syncHistory()
res.json({ success: true, result }) res.json({ success: true, result })
} catch (error) { } catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
} }
@ -612,19 +383,6 @@ const getLabels = async (req, res) => {
/* /*
#swagger.summary = 'Return all labels' #swagger.summary = 'Return all labels'
#swagger.description = 'Return array of all labels assigned to this chat' #swagger.description = 'Return array of all labels assigned to this chat'
#swagger.requestBody = {
required: true,
schema: {
type: 'object',
properties: {
chatId: {
type: 'string',
description: 'Unique WhatsApp identifier for the given Chat (either group or personal)',
example: '6281288888888@c.us'
}
}
}
}
*/ */
try { try {
const { chatId } = req.body const { chatId } = req.body
@ -637,15 +395,6 @@ const getLabels = async (req, res) => {
const labels = await chat.getLabels() const labels = await chat.getLabels()
res.json({ success: true, labels }) res.json({ success: true, labels })
} catch (error) { } catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
} }
@ -695,15 +444,6 @@ const changeLabels = async (req, res) => {
await chat.changeLabels(labelIds) await chat.changeLabels(labelIds)
res.json({ success: true }) res.json({ success: true })
} catch (error) { } catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
} }

View file

@ -119,20 +119,11 @@ const sendMessage = async (req, res) => {
break break
} }
default: default:
return sendErrorResponse(res, 404, 'contentType invalid, must be string, MessageMedia, MessageMediaFromURL, Location, Buttons, List, Contact or Poll') return sendErrorResponse(res, 400, 'contentType invalid, must be string, MessageMedia, MessageMediaFromURL, Location, Buttons, List, Contact or Poll')
} }
res.json({ success: true, message: messageOut }) res.json({ success: true, message: messageOut })
} catch (error) { } catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
console.log(error) console.log(error)
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
@ -157,15 +148,6 @@ const getClassInfo = (req, res) => {
const sessionInfo = client.info const sessionInfo = client.info
res.json({ success: true, sessionInfo }) res.json({ success: true, sessionInfo })
} catch (error) { } catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
} }
@ -205,15 +187,6 @@ const isRegisteredUser = async (req, res) => {
const result = await client.isRegisteredUser(number) const result = await client.isRegisteredUser(number)
res.json({ success: true, result }) res.json({ success: true, result })
} catch (error) { } catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
} }
@ -254,15 +227,6 @@ const getNumberId = async (req, res) => {
const result = await client.getNumberId(number) const result = await client.getNumberId(number)
res.json({ success: true, result }) res.json({ success: true, result })
} catch (error) { } catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
} }
@ -318,15 +282,6 @@ const createGroup = async (req, res) => {
} }
res.json({ success: true, response }) res.json({ success: true, response })
} catch (error) { } catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
} }
@ -354,7 +309,7 @@ const setStatus = async (req, res) => {
status: { status: {
type: 'string', type: 'string',
description: 'New status message', description: 'New status message',
example: 'I\'m running WhatsApp Web Api' example: 'I\'m running WWebJS Api'
}, },
} }
}, },
@ -366,15 +321,6 @@ const setStatus = async (req, res) => {
await client.setStatus(status) await client.setStatus(status)
res.json({ success: true }) res.json({ success: true })
} catch (error) { } catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
} }
@ -397,15 +343,6 @@ const getContacts = async (req, res) => {
const contacts = await client.getContacts() const contacts = await client.getContacts()
res.json({ success: true, contacts }) res.json({ success: true, contacts })
} catch (error) { } catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
} }
@ -433,15 +370,6 @@ const getChats = async (req, res) => {
const chats = await client.getChats() const chats = await client.getChats()
res.json({ success: true, chats }) res.json({ success: true, chats })
} catch (error) { } catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
} }
@ -481,15 +409,6 @@ const getProfilePictureUrl = async (req, res) => {
const result = await client.getProfilePicUrl(contactId) const result = await client.getProfilePicUrl(contactId)
res.json({ success: true, result }) res.json({ success: true, result })
} catch (error) { } catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
} }
@ -530,15 +449,6 @@ const acceptInvite = async (req, res) => {
const acceptInvite = await client.acceptInvite(inviteCode) const acceptInvite = await client.acceptInvite(inviteCode)
res.json({ success: true, acceptInvite }) res.json({ success: true, acceptInvite })
} catch (error) { } catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
} }
@ -564,15 +474,6 @@ const getWWebVersion = async (req, res) => {
const result = await client.getWWebVersion() const result = await client.getWWebVersion()
res.json({ success: true, result }) res.json({ success: true, result })
} catch (error) { } catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
} }
@ -613,15 +514,6 @@ const archiveChat = async (req, res) => {
const result = await client.archiveChat(chatId) const result = await client.archiveChat(chatId)
res.json({ success: true, result }) res.json({ success: true, result })
} catch (error) { } catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
} }
@ -646,15 +538,6 @@ const getBlockedContacts = async (req, res) => {
const blockedContacts = await client.getBlockedContacts() const blockedContacts = await client.getBlockedContacts()
res.json({ success: true, blockedContacts }) res.json({ success: true, blockedContacts })
} catch (error) { } catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
} }
@ -693,20 +576,10 @@ const getChatById = async (req, res) => {
const client = sessions.get(req.params.sessionId) const client = sessions.get(req.params.sessionId)
const chat = await client.getChatById(chatId) const chat = await client.getChatById(chatId)
if (!chat) { if (!chat) {
sendErrorResponse(res, 404, 'Chat not Found') throw new Error('Chat not found')
return
} }
res.json({ success: true, chat }) res.json({ success: true, chat })
} catch (error) { } catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
} }
@ -746,15 +619,6 @@ const getChatLabels = async (req, res) => {
const chatLabels = await client.getChatLabels(chatId) const chatLabels = await client.getChatLabels(chatId)
res.json({ success: true, chatLabels }) res.json({ success: true, chatLabels })
} catch (error) { } catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
} }
@ -794,15 +658,6 @@ const getChatsByLabelId = async (req, res) => {
const chats = await client.getChatsByLabelId(labelId) const chats = await client.getChatsByLabelId(labelId)
res.json({ success: true, chats }) res.json({ success: true, chats })
} catch (error) { } catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
} }
@ -842,15 +697,6 @@ const getCommonGroups = async (req, res) => {
const groups = await client.getCommonGroups(contactId) const groups = await client.getCommonGroups(contactId)
res.json({ success: true, groups }) res.json({ success: true, groups })
} catch (error) { } catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
} }
@ -889,15 +735,6 @@ const getContactById = async (req, res) => {
const contact = await client.getContactById(contactId) const contact = await client.getContactById(contactId)
res.json({ success: true, contact }) res.json({ success: true, contact })
} catch (error) { } catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
} }
@ -937,15 +774,6 @@ const getInviteInfo = async (req, res) => {
const inviteInfo = await client.getInviteInfo(inviteCode) const inviteInfo = await client.getInviteInfo(inviteCode)
res.json({ success: true, inviteInfo }) res.json({ success: true, inviteInfo })
} catch (error) { } catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
} }
@ -985,15 +813,6 @@ const getLabelById = async (req, res) => {
const label = await client.getLabelById(labelId) const label = await client.getLabelById(labelId)
res.json({ success: true, label }) res.json({ success: true, label })
} catch (error) { } catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
} }
@ -1017,15 +836,6 @@ const getLabels = async (req, res) => {
const labels = await client.getLabels() const labels = await client.getLabels()
res.json({ success: true, labels }) res.json({ success: true, labels })
} catch (error) { } catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
} }
@ -1067,15 +877,6 @@ const addOrRemoveLabels = async (req, res) => {
await client.addOrRemoveLabels(labelIds, chatIds) await client.addOrRemoveLabels(labelIds, chatIds)
res.json({ success: true }) res.json({ success: true })
} catch (error) { } catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
} }
@ -1099,15 +900,6 @@ const getState = async (req, res) => {
const state = await client.getState() const state = await client.getState()
res.json({ success: true, state }) res.json({ success: true, state })
} catch (error) { } catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
} }
@ -1147,15 +939,6 @@ const markChatUnread = async (req, res) => {
await client.markChatUnread(chatId) await client.markChatUnread(chatId)
res.json({ success: true }) res.json({ success: true })
} catch (error) { } catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
} }
@ -1206,15 +989,6 @@ const muteChat = async (req, res) => {
} }
res.json({ success: true }) res.json({ success: true })
} catch (error) { } catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
} }
@ -1254,15 +1028,6 @@ const pinChat = async (req, res) => {
const result = await client.pinChat(chatId) const result = await client.pinChat(chatId)
res.json({ success: true, result }) res.json({ success: true, result })
} catch (error) { } catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
} }
@ -1295,7 +1060,7 @@ const searchMessages = async (req, res) => {
options: { options: {
type: 'object', type: 'object',
description: 'Search options', description: 'Search options',
example: {} example: { limit: 10, page: 1 }
}, },
} }
}, },
@ -1312,15 +1077,6 @@ const searchMessages = async (req, res) => {
} }
res.json({ success: true, messages }) res.json({ success: true, messages })
} catch (error) { } catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
} }
@ -1344,15 +1100,6 @@ const sendPresenceAvailable = async (req, res) => {
await client.sendPresenceAvailable() await client.sendPresenceAvailable()
res.json({ success: true }) res.json({ success: true })
} catch (error) { } catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
} }
@ -1376,15 +1123,6 @@ const sendPresenceUnavailable = async (req, res) => {
await client.sendPresenceUnavailable() await client.sendPresenceUnavailable()
res.json({ success: true }) res.json({ success: true })
} catch (error) { } catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
} }
@ -1423,15 +1161,6 @@ const sendSeen = async (req, res) => {
const result = await client.sendSeen(chatId) const result = await client.sendSeen(chatId)
res.json({ success: true, result }) res.json({ success: true, result })
} catch (error) { } catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
} }
@ -1471,15 +1200,6 @@ const setDisplayName = async (req, res) => {
const result = await client.setDisplayName(displayName) const result = await client.setDisplayName(displayName)
res.json({ success: true, result }) res.json({ success: true, result })
} catch (error) { } catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
} }
@ -1518,15 +1238,6 @@ const unarchiveChat = async (req, res) => {
const result = await client.unarchiveChat(chatId) const result = await client.unarchiveChat(chatId)
res.json({ success: true, result }) res.json({ success: true, result })
} catch (error) { } catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
} }
@ -1566,15 +1277,6 @@ const unmuteChat = async (req, res) => {
const result = await client.unmuteChat(chatId) const result = await client.unmuteChat(chatId)
res.json({ success: true, result }) res.json({ success: true, result })
} catch (error) { } catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
} }
@ -1614,15 +1316,6 @@ const unpinChat = async (req, res) => {
const result = await client.unpinChat(chatId) const result = await client.unpinChat(chatId)
res.json({ success: true, result }) res.json({ success: true, result })
} catch (error) { } catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
} }
@ -1667,15 +1360,6 @@ const setProfilePicture = async (req, res) => {
const result = await client.setProfilePicture(media) const result = await client.setProfilePicture(media)
res.json({ success: true, result }) res.json({ success: true, result })
} catch (error) { } catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
} }
@ -1697,15 +1381,6 @@ const deleteProfilePicture = async (req, res) => {
const result = await client.deleteProfilePicture() const result = await client.deleteProfilePicture()
res.json({ success: true, result }) res.json({ success: true, result })
} catch (error) { } catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
} }
@ -1741,15 +1416,6 @@ const setAutoDownloadAudio = async (req, res) => {
await client.setAutoDownloadAudio(flag) await client.setAutoDownloadAudio(flag)
res.json({ success: true }) res.json({ success: true })
} catch (error) { } catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
} }
@ -1785,15 +1451,6 @@ const setAutoDownloadDocuments = async (req, res) => {
await client.setAutoDownloadDocuments(flag) await client.setAutoDownloadDocuments(flag)
res.json({ success: true }) res.json({ success: true })
} catch (error) { } catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
} }
@ -1829,15 +1486,6 @@ const setAutoDownloadPhotos = async (req, res) => {
await client.setAutoDownloadPhotos(flag) await client.setAutoDownloadPhotos(flag)
res.json({ success: true }) res.json({ success: true })
} catch (error) { } catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
} }
@ -1873,15 +1521,6 @@ const setAutoDownloadVideos = async (req, res) => {
await client.setAutoDownloadVideos(flag) await client.setAutoDownloadVideos(flag)
res.json({ success: true }) res.json({ success: true })
} catch (error) { } catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
} }
@ -1921,15 +1560,6 @@ const syncHistory = async (req, res) => {
const result = await client.syncHistory(chatId) const result = await client.syncHistory(chatId)
res.json({ success: true, result }) res.json({ success: true, result })
} catch (error) { } catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
} }
@ -1970,15 +1600,6 @@ const getContactDeviceCount = async (req, res) => {
const result = await client.getContactDeviceCount(userId) const result = await client.getContactDeviceCount(userId)
res.json({ success: true, result }) res.json({ success: true, result })
} catch (error) { } catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
} }
@ -2018,15 +1639,6 @@ const getCountryCode = async (req, res) => {
const result = await client.getCountryCode(number) const result = await client.getCountryCode(number)
res.json({ success: true, result }) res.json({ success: true, result })
} catch (error) { } catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
} }
@ -2066,15 +1678,6 @@ const getFormattedNumber = async (req, res) => {
const result = await client.getFormattedNumber(number) const result = await client.getFormattedNumber(number)
res.json({ success: true, result }) res.json({ success: true, result })
} catch (error) { } catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
} }

View file

@ -14,14 +14,17 @@ const { sendErrorResponse } = require('../utils')
* @returns {Object} The contact information object. * @returns {Object} The contact information object.
*/ */
const getClassInfo = async (req, res) => { const getClassInfo = async (req, res) => {
/*
#swagger.summary = 'Get the contact'
*/
try { try {
const { contactId } = req.body const { contactId } = req.body
const client = sessions.get(req.params.sessionId) const client = sessions.get(req.params.sessionId)
const contact = await client.getContactById(contactId) const contact = await client.getContactById(contactId)
if (!contact) { if (!contact) {
sendErrorResponse(res, 404, 'Contact not Found') throw new Error('Contact not found')
} }
res.json({ success: true, result: contact }) res.json({ success: true, contact })
} catch (error) { } catch (error) {
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
@ -40,12 +43,15 @@ const getClassInfo = async (req, res) => {
* @returns {Object} The result of the blocking operation. * @returns {Object} The result of the blocking operation.
*/ */
const block = async (req, res) => { const block = async (req, res) => {
/*
#swagger.summary = 'Block contact'
*/
try { try {
const { contactId } = req.body const { contactId } = req.body
const client = sessions.get(req.params.sessionId) const client = sessions.get(req.params.sessionId)
const contact = await client.getContactById(contactId) const contact = await client.getContactById(contactId)
if (!contact) { if (!contact) {
sendErrorResponse(res, 404, 'Contact not Found') throw new Error('Contact not found')
} }
const result = await contact.block() const result = await contact.block()
res.json({ success: true, result }) res.json({ success: true, result })
@ -67,12 +73,16 @@ const block = async (req, res) => {
* @returns {Object} The 'About' information of the contact. * @returns {Object} The 'About' information of the contact.
*/ */
const getAbout = async (req, res) => { const getAbout = async (req, res) => {
/*
#swagger.summary = "Get the contact's current info"
#swagger.description = "Get the Contact's current 'about' info. Returns null if you don't have permission to read their status."
*/
try { try {
const { contactId } = req.body const { contactId } = req.body
const client = sessions.get(req.params.sessionId) const client = sessions.get(req.params.sessionId)
const contact = await client.getContactById(contactId) const contact = await client.getContactById(contactId)
if (!contact) { if (!contact) {
sendErrorResponse(res, 404, 'Contact not Found') throw new Error('Contact not found')
} }
const result = await contact.getAbout() const result = await contact.getAbout()
res.json({ success: true, result }) res.json({ success: true, result })
@ -94,11 +104,17 @@ const getAbout = async (req, res) => {
* @returns {Promise<void>} A promise that resolves with the chat information of the contact. * @returns {Promise<void>} A promise that resolves with the chat information of the contact.
*/ */
const getChat = async (req, res) => { const getChat = async (req, res) => {
/*
#swagger.summary = 'Get the chat'
#swagger.description = 'Get the chat that corresponds to the contact. Will return null when getting chat for currently logged in user.'
*/
try { try {
const { contactId } = req.body const { contactId } = req.body
const client = sessions.get(req.params.sessionId) const client = sessions.get(req.params.sessionId)
const contact = await client.getContactById(contactId) const contact = await client.getContactById(contactId)
if (!contact) { sendErrorResponse(res, 404, 'Contact not Found') } if (!contact) {
throw new Error('Contact not found')
}
const result = await contact.getChat() const result = await contact.getChat()
res.json({ success: true, result }) res.json({ success: true, result })
} catch (error) { } catch (error) {
@ -119,11 +135,17 @@ const getChat = async (req, res) => {
* @returns {Promise<void>} A promise that resolves with the formatted number of the contact. * @returns {Promise<void>} A promise that resolves with the formatted number of the contact.
*/ */
const getFormattedNumber = async (req, res) => { const getFormattedNumber = async (req, res) => {
/*
#swagger.summary = 'Get the formatted phone number'
#swagger.description = "Returns the contact's formatted phone number, (12345678901@c.us) => (+1 (234) 5678-901)."
*/
try { try {
const { contactId } = req.body const { contactId } = req.body
const client = sessions.get(req.params.sessionId) const client = sessions.get(req.params.sessionId)
const contact = await client.getContactById(contactId) const contact = await client.getContactById(contactId)
if (!contact) { sendErrorResponse(res, 404, 'Contact not Found') } if (!contact) {
throw new Error('Contact not found')
}
const result = await contact.getFormattedNumber() const result = await contact.getFormattedNumber()
res.json({ success: true, result }) res.json({ success: true, result })
} catch (error) { } catch (error) {
@ -144,11 +166,17 @@ const getFormattedNumber = async (req, res) => {
* @returns {Promise<void>} A promise that resolves with the country code of the contact. * @returns {Promise<void>} A promise that resolves with the country code of the contact.
*/ */
const getCountryCode = async (req, res) => { const getCountryCode = async (req, res) => {
/*
#swagger.summary = 'Get the country code'
#swagger.description = "Returns the contact's country code, (1541859685@c.us) => (1)."
*/
try { try {
const { contactId } = req.body const { contactId } = req.body
const client = sessions.get(req.params.sessionId) const client = sessions.get(req.params.sessionId)
const contact = await client.getContactById(contactId) const contact = await client.getContactById(contactId)
if (!contact) { sendErrorResponse(res, 404, 'Contact not Found') } if (!contact) {
throw new Error('Contact not found')
}
const result = await contact.getCountryCode() const result = await contact.getCountryCode()
res.json({ success: true, result }) res.json({ success: true, result })
} catch (error) { } catch (error) {
@ -169,11 +197,17 @@ const getCountryCode = async (req, res) => {
* @returns {Promise<void>} A promise that resolves with the profile picture url of the contact. * @returns {Promise<void>} A promise that resolves with the profile picture url of the contact.
*/ */
const getProfilePicUrl = async (req, res) => { const getProfilePicUrl = async (req, res) => {
/*
#swagger.summary = 'Get the profile picture URL'
#swagger.description = "Get the contact's profile picture URL, if privacy settings allow it."
*/
try { try {
const { contactId } = req.body const { contactId } = req.body
const client = sessions.get(req.params.sessionId) const client = sessions.get(req.params.sessionId)
const contact = await client.getContactById(contactId) const contact = await client.getContactById(contactId)
if (!contact) { sendErrorResponse(res, 404, 'Contact not Found') } if (!contact) {
throw new Error('Contact not found')
}
const result = await contact.getProfilePicUrl() || null const result = await contact.getProfilePicUrl() || null
res.json({ success: true, result }) res.json({ success: true, result })
} catch (error) { } catch (error) {
@ -194,11 +228,17 @@ const getProfilePicUrl = async (req, res) => {
* @returns {Promise<void>} A promise that resolves with the result of unblocking the contact. * @returns {Promise<void>} A promise that resolves with the result of unblocking the contact.
*/ */
const unblock = async (req, res) => { const unblock = async (req, res) => {
/*
#swagger.summary = 'Unblock the contact'
#swagger.description = "Unblock the contact from WhatsApp."
*/
try { try {
const { contactId } = req.body const { contactId } = req.body
const client = sessions.get(req.params.sessionId) const client = sessions.get(req.params.sessionId)
const contact = await client.getContactById(contactId) const contact = await client.getContactById(contactId)
if (!contact) { sendErrorResponse(res, 404, 'Contact not Found') } if (!contact) {
throw new Error('Contact not found')
}
const result = await contact.unblock() const result = await contact.unblock()
res.json({ success: true, result }) res.json({ success: true, result })
} catch (error) { } catch (error) {
@ -206,6 +246,37 @@ const unblock = async (req, res) => {
} }
} }
/**
* Gets the contact's common groups with you.
*
* @async
* @function unblock
* @param {Object} req - The request object.
* @param {Object} res - The response object.
* @param {string} req.params.sessionId - The session ID.
* @param {string} req.body.contactId - The ID of the client whose contact is being unblocked.
* @throws {Error} If the contact with the given contactId is not found or if there is an error unblocking the contact.
* @returns {Promise<void>} A promise that resolves with the result of unblocking the contact.
*/
const getCommonGroups = async (req, res) => {
/*
#swagger.summary = "Get the contact's common groups"
#swagger.description = "Get the contact's common groups with you. Returns empty array if you don't have any common group."
*/
try {
const { contactId } = req.body
const client = sessions.get(req.params.sessionId)
const contact = await client.getContactById(contactId)
if (!contact) {
throw new Error('Contact not found')
}
const result = await contact.getCommonGroups()
res.json({ success: true, result })
} catch (error) {
sendErrorResponse(res, 500, error.message)
}
}
module.exports = { module.exports = {
getClassInfo, getClassInfo,
block, block,
@ -214,5 +285,6 @@ module.exports = {
unblock, unblock,
getFormattedNumber, getFormattedNumber,
getCountryCode, getCountryCode,
getProfilePicUrl getProfilePicUrl,
getCommonGroups
} }

View file

@ -1,3 +1,4 @@
const { MessageMedia, Location, Buttons, List, Poll } = require('whatsapp-web.js')
const { sessions } = require('../sessions') const { sessions } = require('../sessions')
const { sendErrorResponse } = require('../utils') const { sendErrorResponse } = require('../utils')
@ -14,8 +15,7 @@ const { sendErrorResponse } = require('../utils')
const _getMessageById = async (client, messageId, chatId) => { const _getMessageById = async (client, messageId, chatId) => {
const chat = await client.getChatById(chatId) const chat = await client.getChatById(chatId)
const messages = await chat.fetchMessages({ limit: 100 }) const messages = await chat.fetchMessages({ limit: 100 })
const message = messages.find((message) => { return message.id.id === messageId }) return messages.find((message) => { return message.id.id === messageId })
return message
} }
/** /**
@ -30,11 +30,14 @@ const _getMessageById = async (client, messageId, chatId) => {
* @returns {Promise<void>} - A Promise that resolves with no value when the function completes. * @returns {Promise<void>} - A Promise that resolves with no value when the function completes.
*/ */
const getClassInfo = async (req, res) => { const getClassInfo = async (req, res) => {
/*
#swagger.summary = 'Get message'
*/
try { try {
const { messageId, chatId } = req.body const { messageId, chatId } = req.body
const client = sessions.get(req.params.sessionId) const client = sessions.get(req.params.sessionId)
const message = await _getMessageById(client, messageId, chatId) const message = await _getMessageById(client, messageId, chatId)
if (!message) { throw new Error('Message not Found') } if (!message) { throw new Error('Message not found') }
res.json({ success: true, message }) res.json({ success: true, message })
} catch (error) { } catch (error) {
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
@ -54,11 +57,37 @@ const getClassInfo = async (req, res) => {
* @returns {Promise<void>} - A Promise that resolves with no value when the function completes. * @returns {Promise<void>} - A Promise that resolves with no value when the function completes.
*/ */
const deleteMessage = async (req, res) => { const deleteMessage = async (req, res) => {
/*
#swagger.summary = 'Delete a message from the chat'
#swagger.requestBody = {
required: true,
schema: {
type: 'object',
properties: {
chatId: {
type: 'string',
description: 'The chat id which contains the message',
example: '6281288888888@c.us'
},
messageId: {
type: 'string',
description: 'Unique WhatsApp identifier for the message',
example: 'ABCDEF999999999'
},
everyone: {
type: 'boolean',
description: 'If true and the message is sent by the current user or the user is an admin, will delete it for everyone in the chat.',
example: true
}
}
}
}
*/
try { try {
const { messageId, chatId, everyone } = req.body const { messageId, chatId, everyone } = req.body
const client = sessions.get(req.params.sessionId) const client = sessions.get(req.params.sessionId)
const message = await _getMessageById(client, messageId, chatId) const message = await _getMessageById(client, messageId, chatId)
if (!message) { throw new Error('Message not Found') } if (!message) { throw new Error('Message not found') }
const result = await message.delete(everyone) const result = await message.delete(everyone)
res.json({ success: true, result }) res.json({ success: true, result })
} catch (error) { } catch (error) {
@ -79,12 +108,15 @@ const deleteMessage = async (req, res) => {
* @returns {Promise<void>} - A Promise that resolves with no value when the function completes. * @returns {Promise<void>} - A Promise that resolves with no value when the function completes.
*/ */
const downloadMedia = async (req, res) => { const downloadMedia = async (req, res) => {
/*
#swagger.summary = 'Download attached message media'
*/
try { try {
const { messageId, chatId, everyone } = req.body const { messageId, chatId } = req.body
const client = sessions.get(req.params.sessionId) const client = sessions.get(req.params.sessionId)
const message = await _getMessageById(client, messageId, chatId) const message = await _getMessageById(client, messageId, chatId)
if (!message) { throw new Error('Message not Found') } if (!message) { throw new Error('Message not found') }
const messageMedia = await message.downloadMedia(everyone) const messageMedia = await message.downloadMedia()
res.json({ success: true, messageMedia }) res.json({ success: true, messageMedia })
} catch (error) { } catch (error) {
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
@ -106,11 +138,37 @@ const downloadMedia = async (req, res) => {
* @throws Will throw an error if the message is not found or if there is an error during the forward operation. * @throws Will throw an error if the message is not found or if there is an error during the forward operation.
*/ */
const forward = async (req, res) => { const forward = async (req, res) => {
/*
#swagger.summary = 'Delete a message from the chat'
#swagger.requestBody = {
required: true,
schema: {
type: 'object',
properties: {
chatId: {
type: 'string',
description: 'The chat id which contains the message',
example: '6281288888888@c.us'
},
messageId: {
type: 'string',
description: 'Unique WhatsApp identifier for the message',
example: 'ABCDEF999999999'
},
destinationChatId: {
type: 'string',
description: 'The chat id to forward the message to',
example: '6281288888889@c.us'
}
}
}
}
*/
try { try {
const { messageId, chatId, destinationChatId } = req.body const { messageId, chatId, destinationChatId } = req.body
const client = sessions.get(req.params.sessionId) const client = sessions.get(req.params.sessionId)
const message = await _getMessageById(client, messageId, chatId) const message = await _getMessageById(client, messageId, chatId)
if (!message) { throw new Error('Message not Found') } if (!message) { throw new Error('Message not found') }
const result = await message.forward(destinationChatId) const result = await message.forward(destinationChatId)
res.json({ success: true, result }) res.json({ success: true, result })
} catch (error) { } catch (error) {
@ -132,11 +190,15 @@ const forward = async (req, res) => {
* @throws Will throw an error if the message is not found or if there is an error during the get info operation. * @throws Will throw an error if the message is not found or if there is an error during the get info operation.
*/ */
const getInfo = async (req, res) => { const getInfo = async (req, res) => {
/*
#swagger.summary = 'Get information about message delivery status'
#swagger.description = 'May return null if the message does not exist or is not sent by you.'
*/
try { try {
const { messageId, chatId } = req.body const { messageId, chatId } = req.body
const client = sessions.get(req.params.sessionId) const client = sessions.get(req.params.sessionId)
const message = await _getMessageById(client, messageId, chatId) const message = await _getMessageById(client, messageId, chatId)
if (!message) { throw new Error('Message not Found') } if (!message) { throw new Error('Message not found') }
const info = await message.getInfo() const info = await message.getInfo()
res.json({ success: true, info }) res.json({ success: true, info })
} catch (error) { } catch (error) {
@ -159,11 +221,14 @@ const getInfo = async (req, res) => {
* @throws {Error} - If there's an error retrieving the message or mentions * @throws {Error} - If there's an error retrieving the message or mentions
*/ */
const getMentions = async (req, res) => { const getMentions = async (req, res) => {
/*
#swagger.summary = 'Get the contacts mentioned'
*/
try { try {
const { messageId, chatId } = req.body const { messageId, chatId } = req.body
const client = sessions.get(req.params.sessionId) const client = sessions.get(req.params.sessionId)
const message = await _getMessageById(client, messageId, chatId) const message = await _getMessageById(client, messageId, chatId)
if (!message) { throw new Error('Message not Found') } if (!message) { throw new Error('Message not found') }
const contacts = await message.getMentions() const contacts = await message.getMentions()
res.json({ success: true, contacts }) res.json({ success: true, contacts })
} catch (error) { } catch (error) {
@ -186,11 +251,14 @@ const getMentions = async (req, res) => {
* @throws {Error} - If there's an error retrieving the message or order information * @throws {Error} - If there's an error retrieving the message or order information
*/ */
const getOrder = async (req, res) => { const getOrder = async (req, res) => {
/*
#swagger.summary = 'Get the order details'
*/
try { try {
const { messageId, chatId } = req.body const { messageId, chatId } = req.body
const client = sessions.get(req.params.sessionId) const client = sessions.get(req.params.sessionId)
const message = await _getMessageById(client, messageId, chatId) const message = await _getMessageById(client, messageId, chatId)
if (!message) { throw new Error('Message not Found') } if (!message) { throw new Error('Message not found') }
const order = await message.getOrder() const order = await message.getOrder()
res.json({ success: true, order }) res.json({ success: true, order })
} catch (error) { } catch (error) {
@ -213,11 +281,14 @@ const getOrder = async (req, res) => {
* @throws {Object} If the specified message is not found or if an error occurs during the retrieval process. * @throws {Object} If the specified message is not found or if an error occurs during the retrieval process.
*/ */
const getPayment = async (req, res) => { const getPayment = async (req, res) => {
/*
#swagger.summary = 'Get the payment details'
*/
try { try {
const { messageId, chatId } = req.body const { messageId, chatId } = req.body
const client = sessions.get(req.params.sessionId) const client = sessions.get(req.params.sessionId)
const message = await _getMessageById(client, messageId, chatId) const message = await _getMessageById(client, messageId, chatId)
if (!message) { throw new Error('Message not Found') } if (!message) { throw new Error('Message not found') }
const payment = await message.getPayment() const payment = await message.getPayment()
res.json({ success: true, payment }) res.json({ success: true, payment })
} catch (error) { } catch (error) {
@ -240,11 +311,14 @@ const getPayment = async (req, res) => {
* @throws {Object} If the specified message is not found or if an error occurs during the retrieval process. * @throws {Object} If the specified message is not found or if an error occurs during the retrieval process.
*/ */
const getQuotedMessage = async (req, res) => { const getQuotedMessage = async (req, res) => {
/*
#swagger.summary = 'Get the quoted message'
*/
try { try {
const { messageId, chatId } = req.body const { messageId, chatId } = req.body
const client = sessions.get(req.params.sessionId) const client = sessions.get(req.params.sessionId)
const message = await _getMessageById(client, messageId, chatId) const message = await _getMessageById(client, messageId, chatId)
if (!message) { throw new Error('Message not Found') } if (!message) { throw new Error('Message not found') }
const quotedMessage = await message.getQuotedMessage() const quotedMessage = await message.getQuotedMessage()
res.json({ success: true, quotedMessage }) res.json({ success: true, quotedMessage })
} catch (error) { } catch (error) {
@ -268,11 +342,37 @@ const getQuotedMessage = async (req, res) => {
* @throws {Error} If there was an error during the operation. * @throws {Error} If there was an error during the operation.
*/ */
const react = async (req, res) => { const react = async (req, res) => {
/*
#swagger.summary = 'React with an emoji'
#swagger.requestBody = {
required: true,
schema: {
type: 'object',
properties: {
chatId: {
type: 'string',
description: 'The chat id which contains the message',
example: '6281288888888@c.us'
},
messageId: {
type: 'string',
description: 'Unique WhatsApp identifier for the message',
example: 'ABCDEF999999999'
},
reaction: {
type: 'string',
description: 'Emoji to react with. Send an empty string to remove the reaction.',
example: '👍'
}
}
}
}
*/
try { try {
const { messageId, chatId, reaction } = req.body const { messageId, chatId, reaction = '' } = req.body
const client = sessions.get(req.params.sessionId) const client = sessions.get(req.params.sessionId)
const message = await _getMessageById(client, messageId, chatId) const message = await _getMessageById(client, messageId, chatId)
if (!message) { throw new Error('Message not Found') } if (!message) { throw new Error('Message not found') }
const result = await message.react(reaction) const result = await message.react(reaction)
res.json({ success: true, result }) res.json({ success: true, result })
} catch (error) { } catch (error) {
@ -297,12 +397,95 @@ const react = async (req, res) => {
* @throws {Error} If there was an error during the operation. * @throws {Error} If there was an error during the operation.
*/ */
const reply = async (req, res) => { const reply = async (req, res) => {
/*
#swagger.summary = 'Send a message as a reply'
#swagger.requestBody = {
required: true,
'@content': {
"application/json": {
schema: {
type: 'object',
properties: {
chatId: {
type: 'string',
description: 'The chat id which contains the message',
example: '6281288888888@c.us'
},
messageId: {
type: 'string',
description: 'Unique WhatsApp identifier for the message',
example: 'ABCDEF999999999'
},
contentType: {
type: 'string',
description: 'The type of message content, must be one of the following: string, MessageMedia, MessageMediaFromURL, Location, Contact, Poll, Buttons, or List',
},
content: {
type: 'object',
description: 'The content of the message, can be a string or an object',
},
options: {
type: 'object',
description: 'The message send options',
}
}
},
examples: {
string: { value: { messageId: '3A80E857F9B44AF60C2C', chatId: '6281288888888@c.us', contentType: 'string', content: 'Reply text!' } }
}
}
}
}
*/
try { try {
const { messageId, chatId, content, destinationChatId, options } = req.body const { messageId, chatId, content, contentType, options } = req.body
const client = sessions.get(req.params.sessionId) const client = sessions.get(req.params.sessionId)
const message = await _getMessageById(client, messageId, chatId) const message = await _getMessageById(client, messageId, chatId)
if (!message) { throw new Error('Message not Found') } if (!message) { throw new Error('Message not found') }
const repliedMessage = await message.reply(content, destinationChatId, options) let contentMessage
switch (contentType) {
case 'string':
if (options?.media) {
const media = options.media
media.filename = null
media.filesize = null
options.media = new MessageMedia(media.mimetype, media.data, media.filename, media.filesize)
}
contentMessage = content
break
case 'MessageMediaFromURL': {
contentMessage = await MessageMedia.fromUrl(content, { unsafeMime: true })
break
}
case 'MessageMedia': {
contentMessage = new MessageMedia(content.mimetype, content.data, content.filename, content.filesize)
break
}
case 'Location': {
contentMessage = new Location(content.latitude, content.longitude, content.description)
break
}
case 'Buttons': {
contentMessage = new Buttons(content.body, content.buttons, content.title, content.footer)
break
}
case 'List': {
contentMessage = new List(content.body, content.buttonText, content.sections, content.title, content.footer)
break
}
case 'Contact': {
const contactId = content.contactId.endsWith('@c.us') ? content.contactId : `${content.contactId}@c.us`
contentMessage = await client.getContactById(contactId)
break
}
case 'Poll': {
contentMessage = new Poll(content.pollName, content.pollOptions, content.options)
break
}
default:
return sendErrorResponse(res, 400, 'contentType invalid, must be string, MessageMedia, MessageMediaFromURL, Location, Buttons, List, Contact or Poll')
}
const repliedMessage = await message.reply(contentMessage, chatId, options)
res.json({ success: true, repliedMessage }) res.json({ success: true, repliedMessage })
} catch (error) { } catch (error) {
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
@ -319,14 +502,17 @@ const reply = async (req, res) => {
* @param {string} req.body.messageId - The message ID. * @param {string} req.body.messageId - The message ID.
* @param {string} req.body.chatId - The chat ID. * @param {string} req.body.chatId - The chat ID.
* @returns {Promise} A Promise that resolves with the result of the message.star() call. * @returns {Promise} A Promise that resolves with the result of the message.star() call.
* @throws {Error} If message is not found, it throws an error with the message "Message not Found". * @throws {Error} If message is not found, it throws an error with the message "Message not found".
*/ */
const star = async (req, res) => { const star = async (req, res) => {
/*
#swagger.summary = 'Star the message'
*/
try { try {
const { messageId, chatId } = req.body const { messageId, chatId } = req.body
const client = sessions.get(req.params.sessionId) const client = sessions.get(req.params.sessionId)
const message = await _getMessageById(client, messageId, chatId) const message = await _getMessageById(client, messageId, chatId)
if (!message) { throw new Error('Message not Found') } if (!message) { throw new Error('Message not found') }
const result = await message.star() const result = await message.star()
res.json({ success: true, result }) res.json({ success: true, result })
} catch (error) { } catch (error) {
@ -344,14 +530,17 @@ const star = async (req, res) => {
* @param {string} req.body.messageId - The message ID. * @param {string} req.body.messageId - The message ID.
* @param {string} req.body.chatId - The chat ID. * @param {string} req.body.chatId - The chat ID.
* @returns {Promise} A Promise that resolves with the result of the message.unstar() call. * @returns {Promise} A Promise that resolves with the result of the message.unstar() call.
* @throws {Error} If message is not found, it throws an error with the message "Message not Found". * @throws {Error} If message is not found, it throws an error with the message "Message not found".
*/ */
const unstar = async (req, res) => { const unstar = async (req, res) => {
/*
#swagger.summary = 'Unstar the message'
*/
try { try {
const { messageId, chatId } = req.body const { messageId, chatId } = req.body
const client = sessions.get(req.params.sessionId) const client = sessions.get(req.params.sessionId)
const message = await _getMessageById(client, messageId, chatId) const message = await _getMessageById(client, messageId, chatId)
if (!message) { throw new Error('Message not Found') } if (!message) { throw new Error('Message not found') }
const result = await message.unstar() const result = await message.unstar()
res.json({ success: true, result }) res.json({ success: true, result })
} catch (error) { } catch (error) {
@ -359,6 +548,144 @@ const unstar = async (req, res) => {
} }
} }
/**
* @function getReactions
* @async
* @description Gets the reactions associated with the given message.
* @param {Object} req - The request object.
* @param {Object} res - The response object.
* @param {string} req.params.sessionId - The session ID.
* @param {string} req.body.messageId - The message ID.
* @param {string} req.body.chatId - The chat ID.
* @returns {Promise} A Promise that resolves with the result of the message.getReactions() call.
* @throws {Error} If message is not found, it throws an error with the message "Message not found".
*/
const getReactions = async (req, res) => {
/*
#swagger.summary = 'Get the reactions associated'
*/
try {
const { messageId, chatId } = req.body
const client = sessions.get(req.params.sessionId)
const message = await _getMessageById(client, messageId, chatId)
if (!message) { throw new Error('Message not found') }
const result = await message.getReactions()
res.json({ success: true, result })
} catch (error) {
sendErrorResponse(res, 500, error.message)
}
}
/**
* @function getReactions
* @async
* @description Gets groups mentioned in this message
* @param {Object} req - The request object.
* @param {Object} res - The response object.
* @param {string} req.params.sessionId - The session ID.
* @param {string} req.body.messageId - The message ID.
* @param {string} req.body.chatId - The chat ID.
* @returns {Promise} A Promise that resolves with the result of the message.getReactions() call.
* @throws {Error} If message is not found, it throws an error with the message "Message not found".
*/
const getGroupMentions = async (req, res) => {
/*
#swagger.summary = 'Get groups mentioned in this message'
*/
try {
const { messageId, chatId } = req.body
const client = sessions.get(req.params.sessionId)
const message = await _getMessageById(client, messageId, chatId)
if (!message) { throw new Error('Message not found') }
const result = await message.getGroupMentions()
res.json({ success: true, result })
} catch (error) {
sendErrorResponse(res, 500, error.message)
}
}
/**
* @function edit
* @async
* @description Edits the current message
* @param {Object} req - The request object.
* @param {Object} res - The response object.
* @param {string} req.params.sessionId - The session ID.
* @param {string} req.body.messageId - The message ID.
* @param {string} req.body.chatId - The chat ID.
* @returns {Promise} A Promise that resolves with the result of the message.edit() call.
* @throws {Error} If message is not found, it throws an error with the message "Message not found".
*/
const edit = async (req, res) => {
/*
#swagger.summary = 'Edit the message'
#swagger.requestBody = {
required: true,
schema: {
type: 'object',
properties: {
chatId: {
type: 'string',
description: 'The chat id which contains the message',
example: '6281288888888@c.us'
},
messageId: {
type: 'string',
description: 'Unique WhatsApp identifier for the message',
example: 'ABCDEF999999999'
},
content: {
type: 'string',
description: 'The content of the message',
},
options: {
type: 'object',
description: 'Options used when editing the message',
}
}
}
}
*/
try {
const { messageId, chatId, content, options } = req.body
const client = sessions.get(req.params.sessionId)
const message = await _getMessageById(client, messageId, chatId)
if (!message) { throw new Error('Message not found') }
const editedMessage = await message.edit(content, options)
res.json({ success: true, message: editedMessage })
} catch (error) {
sendErrorResponse(res, 500, error.message)
}
}
/**
* @function getContact
* @async
* @description Gets groups mentioned in this message
* @param {Object} req - The request object.
* @param {Object} res - The response object.
* @param {string} req.params.sessionId - The session ID.
* @param {string} req.body.messageId - The message ID.
* @param {string} req.body.chatId - The chat ID.
* @returns {Promise} A Promise that resolves with the result of the message.getReactions() call.
* @throws {Error} If message is not found, it throws an error with the message "Message not found".
*/
const getContact = async (req, res) => {
/*
#swagger.summary = 'Get the contact'
*/
try {
const { messageId, chatId } = req.body
const client = sessions.get(req.params.sessionId)
const message = await _getMessageById(client, messageId, chatId)
if (!message) { throw new Error('Message not found') }
const contact = await message.getContact()
res.json({ success: true, contact })
} catch (error) {
sendErrorResponse(res, 500, error.message)
}
}
module.exports = { module.exports = {
getClassInfo, getClassInfo,
deleteMessage, deleteMessage,
@ -372,5 +699,9 @@ module.exports = {
react, react,
reply, reply,
star, star,
unstar unstar,
getReactions,
getGroupMentions,
edit,
getContact
} }

View file

@ -45,15 +45,6 @@ const startSession = async (req, res) => {
await waitForNestedObject(setupSessionReturn.client, 'pupPage') await waitForNestedObject(setupSessionReturn.client, 'pupPage')
res.json({ success: true, message: setupSessionReturn.message }) res.json({ success: true, message: setupSessionReturn.message })
} catch (error) { } catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
console.log('startSession ERROR', error) console.log('startSession ERROR', error)
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
@ -88,15 +79,6 @@ const statusSession = async (req, res) => {
res.json(sessionData) res.json(sessionData)
} catch (error) { } catch (error) {
console.log('statusSession ERROR', error) console.log('statusSession ERROR', error)
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
} }
@ -127,15 +109,6 @@ const sessionQrCode = async (req, res) => {
return res.json({ success: false, message: 'qr code not ready or already scanned' }) return res.json({ success: false, message: 'qr code not ready or already scanned' })
} catch (error) { } catch (error) {
console.log('sessionQrCode ERROR', error) console.log('sessionQrCode ERROR', error)
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
} }
@ -177,15 +150,6 @@ const sessionQrCodeImage = async (req, res) => {
return res.json({ success: false, message: 'qr code not ready or already scanned' }) return res.json({ success: false, message: 'qr code not ready or already scanned' })
} catch (error) { } catch (error) {
console.log('sessionQrCodeImage ERROR', error) console.log('sessionQrCodeImage ERROR', error)
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
} }
@ -222,15 +186,6 @@ const restartSession = async (req, res) => {
*/ */
res.json({ success: true, message: 'Restarted successfully' }) res.json({ success: true, message: 'Restarted successfully' })
} catch (error) { } catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
console.log('restartSession ERROR', error) console.log('restartSession ERROR', error)
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
@ -268,15 +223,6 @@ const terminateSession = async (req, res) => {
*/ */
res.json({ success: true, message: 'Logged out successfully' }) res.json({ success: true, message: 'Logged out successfully' })
} catch (error) { } catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
console.log('terminateSession ERROR', error) console.log('terminateSession ERROR', error)
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
@ -308,15 +254,6 @@ const terminateInactiveSessions = async (req, res) => {
*/ */
res.json({ success: true, message: 'Flush completed successfully' }) res.json({ success: true, message: 'Flush completed successfully' })
} catch (error) { } catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
console.log('terminateInactiveSessions ERROR', error) console.log('terminateInactiveSessions ERROR', error)
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
@ -348,15 +285,6 @@ const terminateAllSessions = async (req, res) => {
*/ */
res.json({ success: true, message: 'Flush completed successfully' }) res.json({ success: true, message: 'Flush completed successfully' })
} catch (error) { } catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
console.log('terminateAllSessions ERROR', error) console.log('terminateAllSessions ERROR', error)
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }

View file

@ -78,6 +78,14 @@ const rateLimiter = rateLimiting({
const sessionSwagger = async (req, res, next) => { const sessionSwagger = async (req, res, next) => {
/* /*
#swagger.tags = ['Session'] #swagger.tags = ['Session']
#swagger.responses[500] = {
description: "Server failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/ */
next() next()
} }
@ -85,6 +93,14 @@ const sessionSwagger = async (req, res, next) => {
const clientSwagger = async (req, res, next) => { const clientSwagger = async (req, res, next) => {
/* /*
#swagger.tags = ['Client'] #swagger.tags = ['Client']
#swagger.responses[500] = {
description: "Server failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/ */
next() next()
} }
@ -99,12 +115,20 @@ const contactSwagger = async (req, res, next) => {
properties: { properties: {
contactId: { contactId: {
type: 'string', type: 'string',
description: 'Unique whatsApp identifier for the contact', description: 'Unique WhatsApp ID for the contact',
example: '6281288888888@c.us' example: '6281288888888@c.us'
} }
} }
} }
} }
#swagger.responses[500] = {
description: "Server failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/ */
next() next()
} }
@ -119,12 +143,12 @@ const messageSwagger = async (req, res, next) => {
properties: { properties: {
chatId: { chatId: {
type: 'string', type: 'string',
description: 'The Chat id which contains the message', description: 'The chat id which contains the message',
example: '6281288888888@c.us' example: '6281288888888@c.us'
}, },
messageId: { messageId: {
type: 'string', type: 'string',
description: 'Unique whatsApp identifier for the message', description: 'Unique WhatsApp ID for the message',
example: 'ABCDEF999999999' example: 'ABCDEF999999999'
} }
} }
@ -144,12 +168,20 @@ const chatSwagger = async (req, res, next) => {
properties: { properties: {
chatId: { chatId: {
type: 'string', type: 'string',
description: 'Unique whatsApp identifier for the given Chat (either group or personnal)', description: 'Unique WhatsApp ID for the given chat (either group or personal)',
example: '6281288888888@c.us' example: '6281288888888@c.us'
} }
} }
} }
} }
#swagger.responses[500] = {
description: "Server failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/ */
next() next()
} }
@ -164,7 +196,7 @@ const groupChatSwagger = async (req, res, next) => {
properties: { properties: {
chatId: { chatId: {
type: 'string', type: 'string',
description: 'Unique whatsApp identifier for the given Chat (either group or personnal)', description: 'Unique WhatsApp ID for the given Chat (either group or personal)',
example: '6281288888888@c.us' example: '6281288888888@c.us'
} }
} }

View file

@ -173,6 +173,10 @@ messageRouter.post('/react/:sessionId', [middleware.sessionNameValidation, middl
messageRouter.post('/reply/:sessionId', [middleware.sessionNameValidation, middleware.sessionValidation], messageController.reply) messageRouter.post('/reply/:sessionId', [middleware.sessionNameValidation, middleware.sessionValidation], messageController.reply)
messageRouter.post('/star/:sessionId', [middleware.sessionNameValidation, middleware.sessionValidation], messageController.star) messageRouter.post('/star/:sessionId', [middleware.sessionNameValidation, middleware.sessionValidation], messageController.star)
messageRouter.post('/unstar/:sessionId', [middleware.sessionNameValidation, middleware.sessionValidation], messageController.unstar) messageRouter.post('/unstar/:sessionId', [middleware.sessionNameValidation, middleware.sessionValidation], messageController.unstar)
messageRouter.post('/getReactions/:sessionId', [middleware.sessionNameValidation, middleware.sessionValidation], messageController.getReactions)
messageRouter.post('/getGroupMentions/:sessionId', [middleware.sessionNameValidation, middleware.sessionValidation], messageController.getGroupMentions)
messageRouter.post('/edit/:sessionId', [middleware.sessionNameValidation, middleware.sessionValidation], messageController.edit)
messageRouter.post('/getContact/:sessionId', [middleware.sessionNameValidation, middleware.sessionValidation], messageController.getContact)
/** /**
* ================ * ================
@ -192,6 +196,7 @@ contactRouter.post('/unblock/:sessionId', [middleware.sessionNameValidation, mid
contactRouter.post('/getFormattedNumber/:sessionId', [middleware.sessionNameValidation, middleware.sessionValidation], contactController.getFormattedNumber) contactRouter.post('/getFormattedNumber/:sessionId', [middleware.sessionNameValidation, middleware.sessionValidation], contactController.getFormattedNumber)
contactRouter.post('/getCountryCode/:sessionId', [middleware.sessionNameValidation, middleware.sessionValidation], contactController.getCountryCode) contactRouter.post('/getCountryCode/:sessionId', [middleware.sessionNameValidation, middleware.sessionValidation], contactController.getCountryCode)
contactRouter.post('/getProfilePicUrl/:sessionId', [middleware.sessionNameValidation, middleware.sessionValidation], contactController.getProfilePicUrl) contactRouter.post('/getProfilePicUrl/:sessionId', [middleware.sessionNameValidation, middleware.sessionValidation], contactController.getProfilePicUrl)
contactRouter.post('/getCommonGroups/:sessionId', [middleware.sessionNameValidation, middleware.sessionValidation], contactController.getCommonGroups)
/** /**
* ================ * ================
* SWAGGER ENDPOINTS * SWAGGER ENDPOINTS

View file

@ -36,8 +36,7 @@ const doc = {
description: 'All functions related to the client' description: 'All functions related to the client'
}, },
{ {
name: 'Message', name: 'Message'
description: 'May fail if the message is too old (Only from the last 100 Messages of the given chat)'
} }
], ],
definitions: { definitions: {
@ -68,7 +67,7 @@ const doc = {
}, },
NotFoundResponse: { NotFoundResponse: {
success: false, success: false,
error: 'Some server error' error: 'Not found error'
}, },
ForbiddenResponse: { ForbiddenResponse: {
success: false, success: false,

File diff suppressed because it is too large Load diff