diff --git a/src/controllers/chatController.js b/src/controllers/chatController.js index 0fe1a59..f7edba8 100644 --- a/src/controllers/chatController.js +++ b/src/controllers/chatController.js @@ -16,19 +16,6 @@ const { sendErrorResponse } = require('../utils') const getClassInfo = async (req, res) => { /* #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 { const { chatId } = req.body @@ -40,15 +27,6 @@ const getClassInfo = async (req, res) => { } res.json({ success: true, chat }) } catch (error) { - /* #swagger.responses[500] = { - description: "Server Failure.", - content: { - "application/json": { - schema: { "$ref": "#/definitions/ErrorResponse" } - } - } - } - */ sendErrorResponse(res, 500, error.message) } } @@ -68,19 +46,6 @@ const getClassInfo = async (req, res) => { const clearMessages = async (req, res) => { /* #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 { const { chatId } = req.body @@ -93,15 +58,6 @@ const clearMessages = async (req, res) => { const result = await chat.clearMessages() res.json({ success: true, result }) } catch (error) { - /* #swagger.responses[500] = { - description: "Server Failure.", - content: { - "application/json": { - schema: { "$ref": "#/definitions/ErrorResponse" } - } - } - } - */ sendErrorResponse(res, 500, error.message) } } @@ -121,19 +77,6 @@ const clearMessages = async (req, res) => { const clearState = async (req, res) => { /* #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 { const { chatId } = req.body @@ -146,15 +89,6 @@ const clearState = async (req, res) => { const result = await chat.clearState() res.json({ success: true, result }) } catch (error) { - /* #swagger.responses[500] = { - description: "Server Failure.", - content: { - "application/json": { - schema: { "$ref": "#/definitions/ErrorResponse" } - } - } - } - */ sendErrorResponse(res, 500, error.message) } } @@ -175,19 +109,6 @@ const clearState = async (req, res) => { const deleteChat = async (req, res) => { /* #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 { const { chatId } = req.body @@ -200,15 +121,6 @@ const deleteChat = async (req, res) => { const result = await chat.delete() res.json({ success: true, result }) } catch (error) { - /* #swagger.responses[500] = { - description: "Server Failure.", - content: { - "application/json": { - schema: { "$ref": "#/definitions/ErrorResponse" } - } - } - } - */ 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() res.json({ success: true, messages }) } catch (error) { - /* #swagger.responses[500] = { - description: "Server Failure.", - content: { - "application/json": { - schema: { "$ref": "#/definitions/ErrorResponse" } - } - } - } - */ sendErrorResponse(res, 500, error.message) } } @@ -291,19 +194,6 @@ const fetchMessages = async (req, res) => { const getContact = async (req, res) => { /* #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 { const { chatId } = req.body @@ -316,15 +206,6 @@ const getContact = async (req, res) => { const contact = await chat.getContact() res.json({ success: true, contact }) } catch (error) { - /* #swagger.responses[500] = { - description: "Server Failure.", - content: { - "application/json": { - schema: { "$ref": "#/definitions/ErrorResponse" } - } - } - } - */ sendErrorResponse(res, 500, error.message) } } @@ -345,19 +226,6 @@ const sendStateRecording = async (req, res) => { /* #swagger.summary = 'Simulate recording audio' #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 { const { chatId } = req.body @@ -370,15 +238,6 @@ const sendStateRecording = async (req, res) => { const result = await chat.sendStateRecording() res.json({ success: true, result }) } catch (error) { - /* #swagger.responses[500] = { - description: "Server Failure.", - content: { - "application/json": { - schema: { "$ref": "#/definitions/ErrorResponse" } - } - } - } - */ sendErrorResponse(res, 500, error.message) } } @@ -399,19 +258,6 @@ const sendStateTyping = async (req, res) => { /* #swagger.summary = 'Simulate typing in chat' #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 { const { chatId } = req.body @@ -424,15 +270,6 @@ const sendStateTyping = async (req, res) => { const result = await chat.sendStateTyping() res.json({ success: true, result }) } catch (error) { - /* #swagger.responses[500] = { - description: "Server Failure.", - content: { - "application/json": { - schema: { "$ref": "#/definitions/ErrorResponse" } - } - } - } - */ sendErrorResponse(res, 500, error.message) } } @@ -452,19 +289,6 @@ const sendStateTyping = async (req, res) => { const sendSeen = async (req, res) => { /* #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 { const { chatId } = req.body @@ -477,15 +301,6 @@ const sendSeen = async (req, res) => { const result = await chat.sendSeen() res.json({ success: true, result }) } catch (error) { - /* #swagger.responses[500] = { - description: "Server Failure.", - content: { - "application/json": { - schema: { "$ref": "#/definitions/ErrorResponse" } - } - } - } - */ sendErrorResponse(res, 500, error.message) } } @@ -505,19 +320,6 @@ const sendSeen = async (req, res) => { const markUnread = async (req, res) => { /* #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 { const { chatId } = req.body @@ -530,15 +332,6 @@ const markUnread = async (req, res) => { const result = await chat.markUnread() res.json({ success: true, result }) } catch (error) { - /* #swagger.responses[500] = { - description: "Server Failure.", - content: { - "application/json": { - schema: { "$ref": "#/definitions/ErrorResponse" } - } - } - } - */ sendErrorResponse(res, 500, error.message) } } @@ -558,19 +351,6 @@ const markUnread = async (req, res) => { const syncHistory = async (req, res) => { /* #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 { const { chatId } = req.body @@ -583,15 +363,6 @@ const syncHistory = async (req, res) => { const result = await chat.syncHistory() res.json({ success: true, result }) } catch (error) { - /* #swagger.responses[500] = { - description: "Server Failure.", - content: { - "application/json": { - schema: { "$ref": "#/definitions/ErrorResponse" } - } - } - } - */ sendErrorResponse(res, 500, error.message) } } @@ -612,19 +383,6 @@ const getLabels = async (req, res) => { /* #swagger.summary = 'Return all labels' #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 { const { chatId } = req.body @@ -637,15 +395,6 @@ const getLabels = async (req, res) => { const labels = await chat.getLabels() res.json({ success: true, labels }) } catch (error) { - /* #swagger.responses[500] = { - description: "Server Failure.", - content: { - "application/json": { - schema: { "$ref": "#/definitions/ErrorResponse" } - } - } - } - */ sendErrorResponse(res, 500, error.message) } } @@ -695,15 +444,6 @@ const changeLabels = async (req, res) => { await chat.changeLabels(labelIds) res.json({ success: true }) } catch (error) { - /* #swagger.responses[500] = { - description: "Server Failure.", - content: { - "application/json": { - schema: { "$ref": "#/definitions/ErrorResponse" } - } - } - } - */ sendErrorResponse(res, 500, error.message) } } diff --git a/src/controllers/clientController.js b/src/controllers/clientController.js index 3c0fc81..4ad7a9a 100644 --- a/src/controllers/clientController.js +++ b/src/controllers/clientController.js @@ -119,20 +119,11 @@ const sendMessage = async (req, res) => { break } 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 }) } catch (error) { - /* #swagger.responses[500] = { - description: "Server Failure.", - content: { - "application/json": { - schema: { "$ref": "#/definitions/ErrorResponse" } - } - } - } - */ console.log(error) sendErrorResponse(res, 500, error.message) } @@ -157,15 +148,6 @@ const getClassInfo = (req, res) => { const sessionInfo = client.info res.json({ success: true, sessionInfo }) } catch (error) { - /* #swagger.responses[500] = { - description: "Server Failure.", - content: { - "application/json": { - schema: { "$ref": "#/definitions/ErrorResponse" } - } - } - } - */ sendErrorResponse(res, 500, error.message) } } @@ -205,15 +187,6 @@ const isRegisteredUser = async (req, res) => { const result = await client.isRegisteredUser(number) res.json({ success: true, result }) } catch (error) { - /* #swagger.responses[500] = { - description: "Server Failure.", - content: { - "application/json": { - schema: { "$ref": "#/definitions/ErrorResponse" } - } - } - } - */ sendErrorResponse(res, 500, error.message) } } @@ -254,15 +227,6 @@ const getNumberId = async (req, res) => { const result = await client.getNumberId(number) res.json({ success: true, result }) } catch (error) { - /* #swagger.responses[500] = { - description: "Server Failure.", - content: { - "application/json": { - schema: { "$ref": "#/definitions/ErrorResponse" } - } - } - } - */ sendErrorResponse(res, 500, error.message) } } @@ -318,15 +282,6 @@ const createGroup = async (req, res) => { } res.json({ success: true, response }) } catch (error) { - /* #swagger.responses[500] = { - description: "Server Failure.", - content: { - "application/json": { - schema: { "$ref": "#/definitions/ErrorResponse" } - } - } - } - */ sendErrorResponse(res, 500, error.message) } } @@ -354,7 +309,7 @@ const setStatus = async (req, res) => { status: { type: 'string', 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) res.json({ success: true }) } catch (error) { - /* #swagger.responses[500] = { - description: "Server Failure.", - content: { - "application/json": { - schema: { "$ref": "#/definitions/ErrorResponse" } - } - } - } - */ sendErrorResponse(res, 500, error.message) } } @@ -397,15 +343,6 @@ const getContacts = async (req, res) => { const contacts = await client.getContacts() res.json({ success: true, contacts }) } catch (error) { - /* #swagger.responses[500] = { - description: "Server Failure.", - content: { - "application/json": { - schema: { "$ref": "#/definitions/ErrorResponse" } - } - } - } - */ sendErrorResponse(res, 500, error.message) } } @@ -433,15 +370,6 @@ const getChats = async (req, res) => { const chats = await client.getChats() res.json({ success: true, chats }) } catch (error) { - /* #swagger.responses[500] = { - description: "Server Failure.", - content: { - "application/json": { - schema: { "$ref": "#/definitions/ErrorResponse" } - } - } - } - */ sendErrorResponse(res, 500, error.message) } } @@ -481,15 +409,6 @@ const getProfilePictureUrl = async (req, res) => { const result = await client.getProfilePicUrl(contactId) res.json({ success: true, result }) } catch (error) { - /* #swagger.responses[500] = { - description: "Server Failure.", - content: { - "application/json": { - schema: { "$ref": "#/definitions/ErrorResponse" } - } - } - } - */ sendErrorResponse(res, 500, error.message) } } @@ -530,15 +449,6 @@ const acceptInvite = async (req, res) => { const acceptInvite = await client.acceptInvite(inviteCode) res.json({ success: true, acceptInvite }) } catch (error) { - /* #swagger.responses[500] = { - description: "Server Failure.", - content: { - "application/json": { - schema: { "$ref": "#/definitions/ErrorResponse" } - } - } - } - */ sendErrorResponse(res, 500, error.message) } } @@ -564,15 +474,6 @@ const getWWebVersion = async (req, res) => { const result = await client.getWWebVersion() res.json({ success: true, result }) } catch (error) { - /* #swagger.responses[500] = { - description: "Server Failure.", - content: { - "application/json": { - schema: { "$ref": "#/definitions/ErrorResponse" } - } - } - } - */ sendErrorResponse(res, 500, error.message) } } @@ -613,15 +514,6 @@ const archiveChat = async (req, res) => { const result = await client.archiveChat(chatId) res.json({ success: true, result }) } catch (error) { - /* #swagger.responses[500] = { - description: "Server Failure.", - content: { - "application/json": { - schema: { "$ref": "#/definitions/ErrorResponse" } - } - } - } - */ sendErrorResponse(res, 500, error.message) } } @@ -646,15 +538,6 @@ const getBlockedContacts = async (req, res) => { const blockedContacts = await client.getBlockedContacts() res.json({ success: true, blockedContacts }) } catch (error) { - /* #swagger.responses[500] = { - description: "Server Failure.", - content: { - "application/json": { - schema: { "$ref": "#/definitions/ErrorResponse" } - } - } - } - */ sendErrorResponse(res, 500, error.message) } } @@ -693,20 +576,10 @@ const getChatById = async (req, res) => { const client = sessions.get(req.params.sessionId) const chat = await client.getChatById(chatId) if (!chat) { - sendErrorResponse(res, 404, 'Chat not Found') - return + throw new Error('Chat not found') } res.json({ success: true, chat }) } catch (error) { - /* #swagger.responses[500] = { - description: "Server Failure.", - content: { - "application/json": { - schema: { "$ref": "#/definitions/ErrorResponse" } - } - } - } - */ sendErrorResponse(res, 500, error.message) } } @@ -746,15 +619,6 @@ const getChatLabels = async (req, res) => { const chatLabels = await client.getChatLabels(chatId) res.json({ success: true, chatLabels }) } catch (error) { - /* #swagger.responses[500] = { - description: "Server Failure.", - content: { - "application/json": { - schema: { "$ref": "#/definitions/ErrorResponse" } - } - } - } - */ sendErrorResponse(res, 500, error.message) } } @@ -794,15 +658,6 @@ const getChatsByLabelId = async (req, res) => { const chats = await client.getChatsByLabelId(labelId) res.json({ success: true, chats }) } catch (error) { - /* #swagger.responses[500] = { - description: "Server Failure.", - content: { - "application/json": { - schema: { "$ref": "#/definitions/ErrorResponse" } - } - } - } - */ sendErrorResponse(res, 500, error.message) } } @@ -842,15 +697,6 @@ const getCommonGroups = async (req, res) => { const groups = await client.getCommonGroups(contactId) res.json({ success: true, groups }) } catch (error) { - /* #swagger.responses[500] = { - description: "Server Failure.", - content: { - "application/json": { - schema: { "$ref": "#/definitions/ErrorResponse" } - } - } - } - */ sendErrorResponse(res, 500, error.message) } } @@ -889,15 +735,6 @@ const getContactById = async (req, res) => { const contact = await client.getContactById(contactId) res.json({ success: true, contact }) } catch (error) { - /* #swagger.responses[500] = { - description: "Server Failure.", - content: { - "application/json": { - schema: { "$ref": "#/definitions/ErrorResponse" } - } - } - } - */ sendErrorResponse(res, 500, error.message) } } @@ -937,15 +774,6 @@ const getInviteInfo = async (req, res) => { const inviteInfo = await client.getInviteInfo(inviteCode) res.json({ success: true, inviteInfo }) } catch (error) { - /* #swagger.responses[500] = { - description: "Server Failure.", - content: { - "application/json": { - schema: { "$ref": "#/definitions/ErrorResponse" } - } - } - } - */ sendErrorResponse(res, 500, error.message) } } @@ -985,15 +813,6 @@ const getLabelById = async (req, res) => { const label = await client.getLabelById(labelId) res.json({ success: true, label }) } catch (error) { - /* #swagger.responses[500] = { - description: "Server Failure.", - content: { - "application/json": { - schema: { "$ref": "#/definitions/ErrorResponse" } - } - } - } - */ sendErrorResponse(res, 500, error.message) } } @@ -1017,15 +836,6 @@ const getLabels = async (req, res) => { const labels = await client.getLabels() res.json({ success: true, labels }) } catch (error) { - /* #swagger.responses[500] = { - description: "Server Failure.", - content: { - "application/json": { - schema: { "$ref": "#/definitions/ErrorResponse" } - } - } - } - */ sendErrorResponse(res, 500, error.message) } } @@ -1067,15 +877,6 @@ const addOrRemoveLabels = async (req, res) => { await client.addOrRemoveLabels(labelIds, chatIds) res.json({ success: true }) } catch (error) { - /* #swagger.responses[500] = { - description: "Server Failure.", - content: { - "application/json": { - schema: { "$ref": "#/definitions/ErrorResponse" } - } - } - } - */ sendErrorResponse(res, 500, error.message) } } @@ -1099,15 +900,6 @@ const getState = async (req, res) => { const state = await client.getState() res.json({ success: true, state }) } catch (error) { - /* #swagger.responses[500] = { - description: "Server Failure.", - content: { - "application/json": { - schema: { "$ref": "#/definitions/ErrorResponse" } - } - } - } - */ sendErrorResponse(res, 500, error.message) } } @@ -1147,15 +939,6 @@ const markChatUnread = async (req, res) => { await client.markChatUnread(chatId) res.json({ success: true }) } catch (error) { - /* #swagger.responses[500] = { - description: "Server Failure.", - content: { - "application/json": { - schema: { "$ref": "#/definitions/ErrorResponse" } - } - } - } - */ sendErrorResponse(res, 500, error.message) } } @@ -1206,15 +989,6 @@ const muteChat = async (req, res) => { } res.json({ success: true }) } catch (error) { - /* #swagger.responses[500] = { - description: "Server Failure.", - content: { - "application/json": { - schema: { "$ref": "#/definitions/ErrorResponse" } - } - } - } - */ sendErrorResponse(res, 500, error.message) } } @@ -1254,15 +1028,6 @@ const pinChat = async (req, res) => { const result = await client.pinChat(chatId) res.json({ success: true, result }) } catch (error) { - /* #swagger.responses[500] = { - description: "Server Failure.", - content: { - "application/json": { - schema: { "$ref": "#/definitions/ErrorResponse" } - } - } - } - */ sendErrorResponse(res, 500, error.message) } } @@ -1295,7 +1060,7 @@ const searchMessages = async (req, res) => { options: { type: 'object', description: 'Search options', - example: {} + example: { limit: 10, page: 1 } }, } }, @@ -1312,15 +1077,6 @@ const searchMessages = async (req, res) => { } res.json({ success: true, messages }) } catch (error) { - /* #swagger.responses[500] = { - description: "Server Failure.", - content: { - "application/json": { - schema: { "$ref": "#/definitions/ErrorResponse" } - } - } - } - */ sendErrorResponse(res, 500, error.message) } } @@ -1344,15 +1100,6 @@ const sendPresenceAvailable = async (req, res) => { await client.sendPresenceAvailable() res.json({ success: true }) } catch (error) { - /* #swagger.responses[500] = { - description: "Server Failure.", - content: { - "application/json": { - schema: { "$ref": "#/definitions/ErrorResponse" } - } - } - } - */ sendErrorResponse(res, 500, error.message) } } @@ -1376,15 +1123,6 @@ const sendPresenceUnavailable = async (req, res) => { await client.sendPresenceUnavailable() res.json({ success: true }) } catch (error) { - /* #swagger.responses[500] = { - description: "Server Failure.", - content: { - "application/json": { - schema: { "$ref": "#/definitions/ErrorResponse" } - } - } - } - */ sendErrorResponse(res, 500, error.message) } } @@ -1423,15 +1161,6 @@ const sendSeen = async (req, res) => { const result = await client.sendSeen(chatId) res.json({ success: true, result }) } catch (error) { - /* #swagger.responses[500] = { - description: "Server Failure.", - content: { - "application/json": { - schema: { "$ref": "#/definitions/ErrorResponse" } - } - } - } - */ sendErrorResponse(res, 500, error.message) } } @@ -1471,15 +1200,6 @@ const setDisplayName = async (req, res) => { const result = await client.setDisplayName(displayName) res.json({ success: true, result }) } catch (error) { - /* #swagger.responses[500] = { - description: "Server Failure.", - content: { - "application/json": { - schema: { "$ref": "#/definitions/ErrorResponse" } - } - } - } - */ sendErrorResponse(res, 500, error.message) } } @@ -1518,15 +1238,6 @@ const unarchiveChat = async (req, res) => { const result = await client.unarchiveChat(chatId) res.json({ success: true, result }) } catch (error) { - /* #swagger.responses[500] = { - description: "Server Failure.", - content: { - "application/json": { - schema: { "$ref": "#/definitions/ErrorResponse" } - } - } - } - */ sendErrorResponse(res, 500, error.message) } } @@ -1566,15 +1277,6 @@ const unmuteChat = async (req, res) => { const result = await client.unmuteChat(chatId) res.json({ success: true, result }) } catch (error) { - /* #swagger.responses[500] = { - description: "Server Failure.", - content: { - "application/json": { - schema: { "$ref": "#/definitions/ErrorResponse" } - } - } - } - */ sendErrorResponse(res, 500, error.message) } } @@ -1614,15 +1316,6 @@ const unpinChat = async (req, res) => { const result = await client.unpinChat(chatId) res.json({ success: true, result }) } catch (error) { - /* #swagger.responses[500] = { - description: "Server Failure.", - content: { - "application/json": { - schema: { "$ref": "#/definitions/ErrorResponse" } - } - } - } - */ sendErrorResponse(res, 500, error.message) } } @@ -1667,15 +1360,6 @@ const setProfilePicture = async (req, res) => { const result = await client.setProfilePicture(media) res.json({ success: true, result }) } catch (error) { - /* #swagger.responses[500] = { - description: "Server Failure.", - content: { - "application/json": { - schema: { "$ref": "#/definitions/ErrorResponse" } - } - } - } - */ sendErrorResponse(res, 500, error.message) } } @@ -1697,15 +1381,6 @@ const deleteProfilePicture = async (req, res) => { const result = await client.deleteProfilePicture() res.json({ success: true, result }) } catch (error) { - /* #swagger.responses[500] = { - description: "Server Failure.", - content: { - "application/json": { - schema: { "$ref": "#/definitions/ErrorResponse" } - } - } - } - */ sendErrorResponse(res, 500, error.message) } } @@ -1741,15 +1416,6 @@ const setAutoDownloadAudio = async (req, res) => { await client.setAutoDownloadAudio(flag) res.json({ success: true }) } catch (error) { - /* #swagger.responses[500] = { - description: "Server Failure.", - content: { - "application/json": { - schema: { "$ref": "#/definitions/ErrorResponse" } - } - } - } - */ sendErrorResponse(res, 500, error.message) } } @@ -1785,15 +1451,6 @@ const setAutoDownloadDocuments = async (req, res) => { await client.setAutoDownloadDocuments(flag) res.json({ success: true }) } catch (error) { - /* #swagger.responses[500] = { - description: "Server Failure.", - content: { - "application/json": { - schema: { "$ref": "#/definitions/ErrorResponse" } - } - } - } - */ sendErrorResponse(res, 500, error.message) } } @@ -1829,15 +1486,6 @@ const setAutoDownloadPhotos = async (req, res) => { await client.setAutoDownloadPhotos(flag) res.json({ success: true }) } catch (error) { - /* #swagger.responses[500] = { - description: "Server Failure.", - content: { - "application/json": { - schema: { "$ref": "#/definitions/ErrorResponse" } - } - } - } - */ sendErrorResponse(res, 500, error.message) } } @@ -1873,15 +1521,6 @@ const setAutoDownloadVideos = async (req, res) => { await client.setAutoDownloadVideos(flag) res.json({ success: true }) } catch (error) { - /* #swagger.responses[500] = { - description: "Server Failure.", - content: { - "application/json": { - schema: { "$ref": "#/definitions/ErrorResponse" } - } - } - } - */ sendErrorResponse(res, 500, error.message) } } @@ -1921,15 +1560,6 @@ const syncHistory = async (req, res) => { const result = await client.syncHistory(chatId) res.json({ success: true, result }) } catch (error) { - /* #swagger.responses[500] = { - description: "Server Failure.", - content: { - "application/json": { - schema: { "$ref": "#/definitions/ErrorResponse" } - } - } - } - */ sendErrorResponse(res, 500, error.message) } } @@ -1970,15 +1600,6 @@ const getContactDeviceCount = async (req, res) => { const result = await client.getContactDeviceCount(userId) res.json({ success: true, result }) } catch (error) { - /* #swagger.responses[500] = { - description: "Server Failure.", - content: { - "application/json": { - schema: { "$ref": "#/definitions/ErrorResponse" } - } - } - } - */ sendErrorResponse(res, 500, error.message) } } @@ -2018,15 +1639,6 @@ const getCountryCode = async (req, res) => { const result = await client.getCountryCode(number) res.json({ success: true, result }) } catch (error) { - /* #swagger.responses[500] = { - description: "Server Failure.", - content: { - "application/json": { - schema: { "$ref": "#/definitions/ErrorResponse" } - } - } - } - */ sendErrorResponse(res, 500, error.message) } } @@ -2066,15 +1678,6 @@ const getFormattedNumber = async (req, res) => { const result = await client.getFormattedNumber(number) res.json({ success: true, result }) } catch (error) { - /* #swagger.responses[500] = { - description: "Server Failure.", - content: { - "application/json": { - schema: { "$ref": "#/definitions/ErrorResponse" } - } - } - } - */ sendErrorResponse(res, 500, error.message) } } diff --git a/src/controllers/contactController.js b/src/controllers/contactController.js index dfa874f..56a2b3a 100644 --- a/src/controllers/contactController.js +++ b/src/controllers/contactController.js @@ -14,14 +14,17 @@ const { sendErrorResponse } = require('../utils') * @returns {Object} The contact information object. */ const getClassInfo = async (req, res) => { + /* + #swagger.summary = 'Get the contact' + */ try { const { contactId } = req.body const client = sessions.get(req.params.sessionId) const contact = await client.getContactById(contactId) 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) { sendErrorResponse(res, 500, error.message) } @@ -40,12 +43,15 @@ const getClassInfo = async (req, res) => { * @returns {Object} The result of the blocking operation. */ const block = async (req, res) => { + /* + #swagger.summary = 'Block contact' + */ try { const { contactId } = req.body const client = sessions.get(req.params.sessionId) const contact = await client.getContactById(contactId) if (!contact) { - sendErrorResponse(res, 404, 'Contact not Found') + throw new Error('Contact not found') } const result = await contact.block() res.json({ success: true, result }) @@ -67,12 +73,16 @@ const block = async (req, res) => { * @returns {Object} The 'About' information of the contact. */ 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 { const { contactId } = req.body const client = sessions.get(req.params.sessionId) const contact = await client.getContactById(contactId) if (!contact) { - sendErrorResponse(res, 404, 'Contact not Found') + throw new Error('Contact not found') } const result = await contact.getAbout() res.json({ success: true, result }) @@ -94,11 +104,17 @@ const getAbout = async (req, res) => { * @returns {Promise} A promise that resolves with the chat information of the contact. */ 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 { const { contactId } = req.body const client = sessions.get(req.params.sessionId) 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() res.json({ success: true, result }) } catch (error) { @@ -119,11 +135,17 @@ const getChat = async (req, res) => { * @returns {Promise} A promise that resolves with the formatted number of the contact. */ 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 { const { contactId } = req.body const client = sessions.get(req.params.sessionId) 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() res.json({ success: true, result }) } catch (error) { @@ -144,11 +166,17 @@ const getFormattedNumber = async (req, res) => { * @returns {Promise} A promise that resolves with the country code of the contact. */ const getCountryCode = async (req, res) => { + /* + #swagger.summary = 'Get the country code' + #swagger.description = "Returns the contact's country code, (1541859685@c.us) => (1)." + */ try { const { contactId } = req.body const client = sessions.get(req.params.sessionId) 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() res.json({ success: true, result }) } catch (error) { @@ -169,11 +197,17 @@ const getCountryCode = async (req, res) => { * @returns {Promise} A promise that resolves with the profile picture url of the contact. */ 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 { const { contactId } = req.body const client = sessions.get(req.params.sessionId) 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 res.json({ success: true, result }) } catch (error) { @@ -194,11 +228,17 @@ const getProfilePicUrl = async (req, res) => { * @returns {Promise} A promise that resolves with the result of unblocking the contact. */ const unblock = async (req, res) => { + /* + #swagger.summary = 'Unblock the contact' + #swagger.description = "Unblock the contact from WhatsApp." + */ try { const { contactId } = req.body const client = sessions.get(req.params.sessionId) 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() res.json({ success: true, result }) } 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} 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 = { getClassInfo, block, @@ -214,5 +285,6 @@ module.exports = { unblock, getFormattedNumber, getCountryCode, - getProfilePicUrl + getProfilePicUrl, + getCommonGroups } diff --git a/src/controllers/messageController.js b/src/controllers/messageController.js index 241d62f..e216b7f 100644 --- a/src/controllers/messageController.js +++ b/src/controllers/messageController.js @@ -1,3 +1,4 @@ +const { MessageMedia, Location, Buttons, List, Poll } = require('whatsapp-web.js') const { sessions } = require('../sessions') const { sendErrorResponse } = require('../utils') @@ -14,8 +15,7 @@ const { sendErrorResponse } = require('../utils') const _getMessageById = async (client, messageId, chatId) => { const chat = await client.getChatById(chatId) const messages = await chat.fetchMessages({ limit: 100 }) - const message = messages.find((message) => { return message.id.id === messageId }) - return message + return messages.find((message) => { return message.id.id === messageId }) } /** @@ -30,11 +30,14 @@ const _getMessageById = async (client, messageId, chatId) => { * @returns {Promise} - A Promise that resolves with no value when the function completes. */ const getClassInfo = async (req, res) => { + /* + #swagger.summary = 'Get 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') } + if (!message) { throw new Error('Message not found') } res.json({ success: true, message }) } catch (error) { sendErrorResponse(res, 500, error.message) @@ -54,11 +57,37 @@ const getClassInfo = async (req, res) => { * @returns {Promise} - A Promise that resolves with no value when the function completes. */ 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 { const { messageId, chatId, everyone } = req.body const client = sessions.get(req.params.sessionId) 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) res.json({ success: true, result }) } catch (error) { @@ -79,12 +108,15 @@ const deleteMessage = async (req, res) => { * @returns {Promise} - A Promise that resolves with no value when the function completes. */ const downloadMedia = async (req, res) => { + /* + #swagger.summary = 'Download attached message media' + */ try { - const { messageId, chatId, everyone } = req.body + 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 messageMedia = await message.downloadMedia(everyone) + if (!message) { throw new Error('Message not found') } + const messageMedia = await message.downloadMedia() res.json({ success: true, messageMedia }) } catch (error) { 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. */ 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 { const { messageId, chatId, destinationChatId } = req.body const client = sessions.get(req.params.sessionId) 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) res.json({ success: true, result }) } 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. */ 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 { 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') } + if (!message) { throw new Error('Message not found') } const info = await message.getInfo() res.json({ success: true, info }) } catch (error) { @@ -159,11 +221,14 @@ const getInfo = async (req, res) => { * @throws {Error} - If there's an error retrieving the message or mentions */ const getMentions = async (req, res) => { + /* + #swagger.summary = 'Get the contacts mentioned' + */ 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') } + if (!message) { throw new Error('Message not found') } const contacts = await message.getMentions() res.json({ success: true, contacts }) } catch (error) { @@ -186,11 +251,14 @@ const getMentions = async (req, res) => { * @throws {Error} - If there's an error retrieving the message or order information */ const getOrder = async (req, res) => { + /* + #swagger.summary = 'Get the order details' + */ 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') } + if (!message) { throw new Error('Message not found') } const order = await message.getOrder() res.json({ success: true, order }) } 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. */ const getPayment = async (req, res) => { + /* + #swagger.summary = 'Get the payment details' + */ 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') } + if (!message) { throw new Error('Message not found') } const payment = await message.getPayment() res.json({ success: true, payment }) } 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. */ const getQuotedMessage = async (req, res) => { + /* + #swagger.summary = 'Get the quoted 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') } + if (!message) { throw new Error('Message not found') } const quotedMessage = await message.getQuotedMessage() res.json({ success: true, quotedMessage }) } catch (error) { @@ -268,11 +342,37 @@ const getQuotedMessage = async (req, res) => { * @throws {Error} If there was an error during the operation. */ 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 { - const { messageId, chatId, reaction } = req.body + const { messageId, chatId, reaction = '' } = req.body const client = sessions.get(req.params.sessionId) 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) res.json({ success: true, result }) } catch (error) { @@ -297,12 +397,95 @@ const react = async (req, res) => { * @throws {Error} If there was an error during the operation. */ 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 { - const { messageId, chatId, content, destinationChatId, options } = req.body + const { messageId, chatId, content, contentType, 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 repliedMessage = await message.reply(content, destinationChatId, options) + if (!message) { throw new Error('Message not found') } + 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 }) } catch (error) { 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.chatId - The chat ID. * @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) => { + /* + #swagger.summary = 'Star the 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') } + if (!message) { throw new Error('Message not found') } const result = await message.star() res.json({ success: true, result }) } catch (error) { @@ -344,14 +530,17 @@ const star = async (req, res) => { * @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.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) => { + /* + #swagger.summary = 'Unstar the 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') } + if (!message) { throw new Error('Message not found') } const result = await message.unstar() res.json({ success: true, result }) } 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 = { getClassInfo, deleteMessage, @@ -372,5 +699,9 @@ module.exports = { react, reply, star, - unstar + unstar, + getReactions, + getGroupMentions, + edit, + getContact } diff --git a/src/controllers/sessionController.js b/src/controllers/sessionController.js index 8a5ef66..4d4f447 100644 --- a/src/controllers/sessionController.js +++ b/src/controllers/sessionController.js @@ -45,15 +45,6 @@ const startSession = async (req, res) => { await waitForNestedObject(setupSessionReturn.client, 'pupPage') res.json({ success: true, message: setupSessionReturn.message }) } catch (error) { - /* #swagger.responses[500] = { - description: "Server Failure.", - content: { - "application/json": { - schema: { "$ref": "#/definitions/ErrorResponse" } - } - } - } - */ console.log('startSession ERROR', error) sendErrorResponse(res, 500, error.message) } @@ -88,15 +79,6 @@ const statusSession = async (req, res) => { res.json(sessionData) } catch (error) { console.log('statusSession ERROR', error) - /* #swagger.responses[500] = { - description: "Server Failure.", - content: { - "application/json": { - schema: { "$ref": "#/definitions/ErrorResponse" } - } - } - } - */ 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' }) } catch (error) { console.log('sessionQrCode ERROR', error) - /* #swagger.responses[500] = { - description: "Server Failure.", - content: { - "application/json": { - schema: { "$ref": "#/definitions/ErrorResponse" } - } - } - } - */ 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' }) } catch (error) { console.log('sessionQrCodeImage ERROR', error) - /* #swagger.responses[500] = { - description: "Server Failure.", - content: { - "application/json": { - schema: { "$ref": "#/definitions/ErrorResponse" } - } - } - } - */ sendErrorResponse(res, 500, error.message) } } @@ -222,15 +186,6 @@ const restartSession = async (req, res) => { */ res.json({ success: true, message: 'Restarted successfully' }) } catch (error) { - /* #swagger.responses[500] = { - description: "Server Failure.", - content: { - "application/json": { - schema: { "$ref": "#/definitions/ErrorResponse" } - } - } - } - */ console.log('restartSession ERROR', error) sendErrorResponse(res, 500, error.message) } @@ -268,15 +223,6 @@ const terminateSession = async (req, res) => { */ res.json({ success: true, message: 'Logged out successfully' }) } catch (error) { - /* #swagger.responses[500] = { - description: "Server Failure.", - content: { - "application/json": { - schema: { "$ref": "#/definitions/ErrorResponse" } - } - } - } - */ console.log('terminateSession ERROR', error) sendErrorResponse(res, 500, error.message) } @@ -308,15 +254,6 @@ const terminateInactiveSessions = async (req, res) => { */ res.json({ success: true, message: 'Flush completed successfully' }) } catch (error) { - /* #swagger.responses[500] = { - description: "Server Failure.", - content: { - "application/json": { - schema: { "$ref": "#/definitions/ErrorResponse" } - } - } - } - */ console.log('terminateInactiveSessions ERROR', error) sendErrorResponse(res, 500, error.message) } @@ -348,15 +285,6 @@ const terminateAllSessions = async (req, res) => { */ res.json({ success: true, message: 'Flush completed successfully' }) } catch (error) { - /* #swagger.responses[500] = { - description: "Server Failure.", - content: { - "application/json": { - schema: { "$ref": "#/definitions/ErrorResponse" } - } - } - } - */ console.log('terminateAllSessions ERROR', error) sendErrorResponse(res, 500, error.message) } diff --git a/src/middleware.js b/src/middleware.js index 17926ab..86c9436 100644 --- a/src/middleware.js +++ b/src/middleware.js @@ -78,6 +78,14 @@ const rateLimiter = rateLimiting({ const sessionSwagger = async (req, res, next) => { /* #swagger.tags = ['Session'] + #swagger.responses[500] = { + description: "Server failure.", + content: { + "application/json": { + schema: { "$ref": "#/definitions/ErrorResponse" } + } + } + } */ next() } @@ -85,6 +93,14 @@ const sessionSwagger = async (req, res, next) => { const clientSwagger = async (req, res, next) => { /* #swagger.tags = ['Client'] + #swagger.responses[500] = { + description: "Server failure.", + content: { + "application/json": { + schema: { "$ref": "#/definitions/ErrorResponse" } + } + } + } */ next() } @@ -99,12 +115,20 @@ const contactSwagger = async (req, res, next) => { properties: { contactId: { type: 'string', - description: 'Unique whatsApp identifier for the contact', + description: 'Unique WhatsApp ID for the contact', example: '6281288888888@c.us' } } } } + #swagger.responses[500] = { + description: "Server failure.", + content: { + "application/json": { + schema: { "$ref": "#/definitions/ErrorResponse" } + } + } + } */ next() } @@ -119,12 +143,12 @@ const messageSwagger = async (req, res, next) => { properties: { chatId: { type: 'string', - description: 'The Chat id which contains the message', + description: 'The chat id which contains the message', example: '6281288888888@c.us' }, messageId: { type: 'string', - description: 'Unique whatsApp identifier for the message', + description: 'Unique WhatsApp ID for the message', example: 'ABCDEF999999999' } } @@ -144,12 +168,20 @@ const chatSwagger = async (req, res, next) => { properties: { chatId: { 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' } } } } + #swagger.responses[500] = { + description: "Server failure.", + content: { + "application/json": { + schema: { "$ref": "#/definitions/ErrorResponse" } + } + } + } */ next() } @@ -164,7 +196,7 @@ const groupChatSwagger = async (req, res, next) => { properties: { chatId: { 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' } } diff --git a/src/routes.js b/src/routes.js index 4de8f12..f20234f 100644 --- a/src/routes.js +++ b/src/routes.js @@ -173,6 +173,10 @@ messageRouter.post('/react/:sessionId', [middleware.sessionNameValidation, middl messageRouter.post('/reply/:sessionId', [middleware.sessionNameValidation, middleware.sessionValidation], messageController.reply) messageRouter.post('/star/:sessionId', [middleware.sessionNameValidation, middleware.sessionValidation], messageController.star) 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('/getCountryCode/:sessionId', [middleware.sessionNameValidation, middleware.sessionValidation], contactController.getCountryCode) contactRouter.post('/getProfilePicUrl/:sessionId', [middleware.sessionNameValidation, middleware.sessionValidation], contactController.getProfilePicUrl) +contactRouter.post('/getCommonGroups/:sessionId', [middleware.sessionNameValidation, middleware.sessionValidation], contactController.getCommonGroups) /** * ================ * SWAGGER ENDPOINTS diff --git a/swagger.js b/swagger.js index 733704d..b2a1f8d 100644 --- a/swagger.js +++ b/swagger.js @@ -36,8 +36,7 @@ const doc = { description: 'All functions related to the client' }, { - name: 'Message', - description: 'May fail if the message is too old (Only from the last 100 Messages of the given chat)' + name: 'Message' } ], definitions: { @@ -68,7 +67,7 @@ const doc = { }, NotFoundResponse: { success: false, - error: 'Some server error' + error: 'Not found error' }, ForbiddenResponse: { success: false, diff --git a/swagger.json b/swagger.json index b3d89be..bb5e0ce 100644 --- a/swagger.json +++ b/swagger.json @@ -25,8 +25,7 @@ "description": "All functions related to the client" }, { - "name": "Message", - "description": "May fail if the message is too old (Only from the last 100 Messages of the given chat)" + "name": "Message" } ], "paths": { @@ -158,7 +157,7 @@ } }, "500": { - "description": "Server Failure.", + "description": "Server failure.", "content": { "application/json": { "schema": { @@ -226,7 +225,7 @@ } }, "500": { - "description": "Server Failure.", + "description": "Server failure.", "content": { "application/json": { "schema": { @@ -287,7 +286,7 @@ } }, "500": { - "description": "Server Failure.", + "description": "Server failure.", "content": { "application/json": { "schema": { @@ -351,7 +350,7 @@ } }, "500": { - "description": "Server Failure.", + "description": "Server failure.", "content": { "application/json": { "schema": { @@ -419,7 +418,7 @@ } }, "500": { - "description": "Server Failure.", + "description": "Server failure.", "content": { "application/json": { "schema": { @@ -487,7 +486,7 @@ } }, "500": { - "description": "Server Failure.", + "description": "Server failure.", "content": { "application/json": { "schema": { @@ -533,7 +532,7 @@ } }, "500": { - "description": "Server Failure.", + "description": "Server failure.", "content": { "application/json": { "schema": { @@ -579,7 +578,7 @@ } }, "500": { - "description": "Server Failure.", + "description": "Server failure.", "content": { "application/json": { "schema": { @@ -650,7 +649,7 @@ } }, "500": { - "description": "Server Failure.", + "description": "Server failure.", "content": { "application/json": { "schema": { @@ -721,7 +720,7 @@ } }, "500": { - "description": "Server Failure.", + "description": "Server failure.", "content": { "application/json": { "schema": { @@ -821,7 +820,7 @@ } }, "500": { - "description": "Server Failure.", + "description": "Server failure.", "content": { "application/json": { "schema": { @@ -921,7 +920,7 @@ } }, "500": { - "description": "Server Failure.", + "description": "Server failure.", "content": { "application/json": { "schema": { @@ -1041,7 +1040,7 @@ } }, "500": { - "description": "Server Failure.", + "description": "Server failure.", "content": { "application/json": { "schema": { @@ -1112,7 +1111,7 @@ } }, "500": { - "description": "Server Failure.", + "description": "Server failure.", "content": { "application/json": { "schema": { @@ -1212,7 +1211,7 @@ } }, "500": { - "description": "Server Failure.", + "description": "Server failure.", "content": { "application/json": { "schema": { @@ -1312,7 +1311,7 @@ } }, "500": { - "description": "Server Failure.", + "description": "Server failure.", "content": { "application/json": { "schema": { @@ -1383,7 +1382,7 @@ } }, "500": { - "description": "Server Failure.", + "description": "Server failure.", "content": { "application/json": { "schema": { @@ -1483,7 +1482,7 @@ } }, "500": { - "description": "Server Failure.", + "description": "Server failure.", "content": { "application/json": { "schema": { @@ -1583,7 +1582,7 @@ } }, "500": { - "description": "Server Failure.", + "description": "Server failure.", "content": { "application/json": { "schema": { @@ -1683,7 +1682,7 @@ } }, "500": { - "description": "Server Failure.", + "description": "Server failure.", "content": { "application/json": { "schema": { @@ -1754,7 +1753,7 @@ } }, "500": { - "description": "Server Failure.", + "description": "Server failure.", "content": { "application/json": { "schema": { @@ -1854,7 +1853,7 @@ } }, "500": { - "description": "Server Failure.", + "description": "Server failure.", "content": { "application/json": { "schema": { @@ -1954,7 +1953,7 @@ } }, "500": { - "description": "Server Failure.", + "description": "Server failure.", "content": { "application/json": { "schema": { @@ -2025,7 +2024,7 @@ } }, "500": { - "description": "Server Failure.", + "description": "Server failure.", "content": { "application/json": { "schema": { @@ -2135,7 +2134,7 @@ } }, "500": { - "description": "Server Failure.", + "description": "Server failure.", "content": { "application/json": { "schema": { @@ -2235,7 +2234,7 @@ } }, "500": { - "description": "Server Failure.", + "description": "Server failure.", "content": { "application/json": { "schema": { @@ -2335,7 +2334,7 @@ } }, "500": { - "description": "Server Failure.", + "description": "Server failure.", "content": { "application/json": { "schema": { @@ -2425,7 +2424,7 @@ } }, "500": { - "description": "Server Failure.", + "description": "Server failure.", "content": { "application/json": { "schema": { @@ -2496,7 +2495,7 @@ } }, "500": { - "description": "Server Failure.", + "description": "Server failure.", "content": { "application/json": { "schema": { @@ -2596,7 +2595,7 @@ } }, "500": { - "description": "Server Failure.", + "description": "Server failure.", "content": { "application/json": { "schema": { @@ -2706,7 +2705,7 @@ } }, "500": { - "description": "Server Failure.", + "description": "Server failure.", "content": { "application/json": { "schema": { @@ -2806,7 +2805,7 @@ } }, "500": { - "description": "Server Failure.", + "description": "Server failure.", "content": { "application/json": { "schema": { @@ -2836,7 +2835,10 @@ "options": { "type": "object", "description": "Search options", - "example": {} + "example": { + "limit": 10, + "page": 1 + } } } } @@ -2853,7 +2855,10 @@ "options": { "type": "object", "description": "Search options", - "example": {} + "example": { + "limit": 10, + "page": 1 + } } } } @@ -2916,7 +2921,7 @@ } }, "500": { - "description": "Server Failure.", + "description": "Server failure.", "content": { "application/json": { "schema": { @@ -3121,7 +3126,7 @@ } }, "500": { - "description": "Server Failure.", + "description": "Server failure.", "content": { "application/json": { "schema": { @@ -3192,7 +3197,7 @@ } }, "500": { - "description": "Server Failure.", + "description": "Server failure.", "content": { "application/json": { "schema": { @@ -3263,7 +3268,7 @@ } }, "500": { - "description": "Server Failure.", + "description": "Server failure.", "content": { "application/json": { "schema": { @@ -3363,7 +3368,7 @@ } }, "500": { - "description": "Server Failure.", + "description": "Server failure.", "content": { "application/json": { "schema": { @@ -3439,9 +3444,6 @@ } ], "responses": { - "200": { - "description": "OK" - }, "403": { "description": "Forbidden.", "content": { @@ -3473,7 +3475,7 @@ } }, "500": { - "description": "Server Failure.", + "description": "Server failure.", "content": { "application/json": { "schema": { @@ -3573,7 +3575,7 @@ } }, "500": { - "description": "Server Failure.", + "description": "Server failure.", "content": { "application/json": { "schema": { @@ -3598,7 +3600,7 @@ "status": { "type": "string", "description": "New status message", - "example": "I'm running WhatsApp Web Api" + "example": "I'm running WWebJS Api" } } } @@ -3610,7 +3612,7 @@ "status": { "type": "string", "description": "New status message", - "example": "I'm running WhatsApp Web Api" + "example": "I'm running WWebJS Api" } } } @@ -3673,7 +3675,7 @@ } }, "500": { - "description": "Server Failure.", + "description": "Server failure.", "content": { "application/json": { "schema": { @@ -3773,7 +3775,7 @@ } }, "500": { - "description": "Server Failure.", + "description": "Server failure.", "content": { "application/json": { "schema": { @@ -3873,7 +3875,7 @@ } }, "500": { - "description": "Server Failure.", + "description": "Server failure.", "content": { "application/json": { "schema": { @@ -3973,7 +3975,7 @@ } }, "500": { - "description": "Server Failure.", + "description": "Server failure.", "content": { "application/json": { "schema": { @@ -4044,7 +4046,7 @@ } }, "500": { - "description": "Server Failure.", + "description": "Server failure.", "content": { "application/json": { "schema": { @@ -4115,7 +4117,7 @@ } }, "500": { - "description": "Server Failure.", + "description": "Server failure.", "content": { "application/json": { "schema": { @@ -4215,7 +4217,7 @@ } }, "500": { - "description": "Server Failure.", + "description": "Server failure.", "content": { "application/json": { "schema": { @@ -4315,7 +4317,7 @@ } }, "500": { - "description": "Server Failure.", + "description": "Server failure.", "content": { "application/json": { "schema": { @@ -4415,7 +4417,7 @@ } }, "500": { - "description": "Server Failure.", + "description": "Server failure.", "content": { "application/json": { "schema": { @@ -4515,7 +4517,7 @@ } }, "500": { - "description": "Server Failure.", + "description": "Server failure.", "content": { "application/json": { "schema": { @@ -4615,7 +4617,7 @@ } }, "500": { - "description": "Server Failure.", + "description": "Server failure.", "content": { "application/json": { "schema": { @@ -4715,7 +4717,7 @@ } }, "500": { - "description": "Server Failure.", + "description": "Server failure.", "content": { "application/json": { "schema": { @@ -4815,7 +4817,7 @@ } }, "500": { - "description": "Server Failure.", + "description": "Server failure.", "content": { "application/json": { "schema": { @@ -4915,7 +4917,7 @@ } }, "500": { - "description": "Server Failure.", + "description": "Server failure.", "content": { "application/json": { "schema": { @@ -4939,7 +4941,7 @@ "properties": { "chatId": { "type": "string", - "description": "Unique WhatsApp identifier for the given Chat (either group or personal)", + "description": "Unique WhatsApp ID for the given chat (either group or personal)", "example": "6281288888888@c.us" } } @@ -4951,7 +4953,7 @@ "properties": { "chatId": { "type": "string", - "description": "Unique WhatsApp identifier for the given Chat (either group or personal)", + "description": "Unique WhatsApp ID for the given chat (either group or personal)", "example": "6281288888888@c.us" } } @@ -5015,7 +5017,7 @@ } }, "500": { - "description": "Server Failure.", + "description": "Server failure.", "content": { "application/json": { "schema": { @@ -5039,7 +5041,7 @@ "properties": { "chatId": { "type": "string", - "description": "Unique WhatsApp identifier for the given Chat (either group or personal)", + "description": "Unique WhatsApp ID for the given chat (either group or personal)", "example": "6281288888888@c.us" } } @@ -5051,7 +5053,7 @@ "properties": { "chatId": { "type": "string", - "description": "Unique WhatsApp identifier for the given Chat (either group or personal)", + "description": "Unique WhatsApp ID for the given chat (either group or personal)", "example": "6281288888888@c.us" } } @@ -5115,7 +5117,7 @@ } }, "500": { - "description": "Server Failure.", + "description": "Server failure.", "content": { "application/json": { "schema": { @@ -5139,7 +5141,7 @@ "properties": { "chatId": { "type": "string", - "description": "Unique WhatsApp identifier for the given Chat (either group or personal)", + "description": "Unique WhatsApp ID for the given chat (either group or personal)", "example": "6281288888888@c.us" } } @@ -5151,7 +5153,7 @@ "properties": { "chatId": { "type": "string", - "description": "Unique WhatsApp identifier for the given Chat (either group or personal)", + "description": "Unique WhatsApp ID for the given chat (either group or personal)", "example": "6281288888888@c.us" } } @@ -5215,7 +5217,7 @@ } }, "500": { - "description": "Server Failure.", + "description": "Server failure.", "content": { "application/json": { "schema": { @@ -5239,7 +5241,7 @@ "properties": { "chatId": { "type": "string", - "description": "Unique WhatsApp identifier for the given Chat (either group or personal)", + "description": "Unique WhatsApp ID for the given chat (either group or personal)", "example": "6281288888888@c.us" } } @@ -5251,7 +5253,7 @@ "properties": { "chatId": { "type": "string", - "description": "Unique WhatsApp identifier for the given Chat (either group or personal)", + "description": "Unique WhatsApp ID for the given chat (either group or personal)", "example": "6281288888888@c.us" } } @@ -5315,7 +5317,7 @@ } }, "500": { - "description": "Server Failure.", + "description": "Server failure.", "content": { "application/json": { "schema": { @@ -5431,7 +5433,7 @@ } }, "500": { - "description": "Server Failure.", + "description": "Server failure.", "content": { "application/json": { "schema": { @@ -5455,7 +5457,7 @@ "properties": { "chatId": { "type": "string", - "description": "Unique WhatsApp identifier for the given Chat (either group or personal)", + "description": "Unique WhatsApp ID for the given chat (either group or personal)", "example": "6281288888888@c.us" } } @@ -5467,7 +5469,7 @@ "properties": { "chatId": { "type": "string", - "description": "Unique WhatsApp identifier for the given Chat (either group or personal)", + "description": "Unique WhatsApp ID for the given chat (either group or personal)", "example": "6281288888888@c.us" } } @@ -5531,7 +5533,7 @@ } }, "500": { - "description": "Server Failure.", + "description": "Server failure.", "content": { "application/json": { "schema": { @@ -5555,7 +5557,7 @@ "properties": { "chatId": { "type": "string", - "description": "Unique WhatsApp identifier for the given Chat (either group or personal)", + "description": "Unique WhatsApp ID for the given chat (either group or personal)", "example": "6281288888888@c.us" } } @@ -5567,7 +5569,7 @@ "properties": { "chatId": { "type": "string", - "description": "Unique WhatsApp identifier for the given Chat (either group or personal)", + "description": "Unique WhatsApp ID for the given chat (either group or personal)", "example": "6281288888888@c.us" } } @@ -5631,7 +5633,7 @@ } }, "500": { - "description": "Server Failure.", + "description": "Server failure.", "content": { "application/json": { "schema": { @@ -5655,7 +5657,7 @@ "properties": { "chatId": { "type": "string", - "description": "Unique WhatsApp identifier for the given Chat (either group or personal)", + "description": "Unique WhatsApp ID for the given chat (either group or personal)", "example": "6281288888888@c.us" } } @@ -5667,7 +5669,7 @@ "properties": { "chatId": { "type": "string", - "description": "Unique WhatsApp identifier for the given Chat (either group or personal)", + "description": "Unique WhatsApp ID for the given chat (either group or personal)", "example": "6281288888888@c.us" } } @@ -5731,7 +5733,7 @@ } }, "500": { - "description": "Server Failure.", + "description": "Server failure.", "content": { "application/json": { "schema": { @@ -5755,7 +5757,7 @@ "properties": { "chatId": { "type": "string", - "description": "Unique WhatsApp identifier for the given Chat (either group or personal)", + "description": "Unique WhatsApp ID for the given chat (either group or personal)", "example": "6281288888888@c.us" } } @@ -5767,7 +5769,7 @@ "properties": { "chatId": { "type": "string", - "description": "Unique WhatsApp identifier for the given Chat (either group or personal)", + "description": "Unique WhatsApp ID for the given chat (either group or personal)", "example": "6281288888888@c.us" } } @@ -5831,7 +5833,7 @@ } }, "500": { - "description": "Server Failure.", + "description": "Server failure.", "content": { "application/json": { "schema": { @@ -5855,7 +5857,7 @@ "properties": { "chatId": { "type": "string", - "description": "Unique WhatsApp identifier for the given Chat (either group or personal)", + "description": "Unique WhatsApp ID for the given chat (either group or personal)", "example": "6281288888888@c.us" } } @@ -5867,7 +5869,7 @@ "properties": { "chatId": { "type": "string", - "description": "Unique WhatsApp identifier for the given Chat (either group or personal)", + "description": "Unique WhatsApp ID for the given chat (either group or personal)", "example": "6281288888888@c.us" } } @@ -5931,7 +5933,7 @@ } }, "500": { - "description": "Server Failure.", + "description": "Server failure.", "content": { "application/json": { "schema": { @@ -5955,7 +5957,7 @@ "properties": { "chatId": { "type": "string", - "description": "Unique WhatsApp identifier for the given Chat (either group or personal)", + "description": "Unique WhatsApp ID for the given chat (either group or personal)", "example": "6281288888888@c.us" } } @@ -5967,7 +5969,7 @@ "properties": { "chatId": { "type": "string", - "description": "Unique WhatsApp identifier for the given Chat (either group or personal)", + "description": "Unique WhatsApp ID for the given chat (either group or personal)", "example": "6281288888888@c.us" } } @@ -6031,7 +6033,7 @@ } }, "500": { - "description": "Server Failure.", + "description": "Server failure.", "content": { "application/json": { "schema": { @@ -6055,7 +6057,7 @@ "properties": { "chatId": { "type": "string", - "description": "Unique WhatsApp identifier for the given Chat (either group or personal)", + "description": "Unique WhatsApp ID for the given chat (either group or personal)", "example": "6281288888888@c.us" } } @@ -6067,7 +6069,7 @@ "properties": { "chatId": { "type": "string", - "description": "Unique WhatsApp identifier for the given Chat (either group or personal)", + "description": "Unique WhatsApp ID for the given chat (either group or personal)", "example": "6281288888888@c.us" } } @@ -6131,7 +6133,7 @@ } }, "500": { - "description": "Server Failure.", + "description": "Server failure.", "content": { "application/json": { "schema": { @@ -6244,6 +6246,16 @@ } } } + }, + "500": { + "description": "Server failure.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } } }, "security": [ @@ -6260,7 +6272,7 @@ "properties": { "chatId": { "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" } } @@ -6272,7 +6284,7 @@ "properties": { "chatId": { "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" } } @@ -6333,6 +6345,16 @@ } } } + }, + "500": { + "description": "Server failure.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } } }, "security": [ @@ -6349,7 +6371,7 @@ "properties": { "chatId": { "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" } } @@ -6361,7 +6383,7 @@ "properties": { "chatId": { "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" } } @@ -6422,6 +6444,16 @@ } } } + }, + "500": { + "description": "Server failure.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } } }, "security": [ @@ -6438,7 +6470,7 @@ "properties": { "chatId": { "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" } } @@ -6450,7 +6482,7 @@ "properties": { "chatId": { "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" } } @@ -6511,6 +6543,16 @@ } } } + }, + "500": { + "description": "Server failure.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } } }, "security": [ @@ -6527,7 +6569,7 @@ "properties": { "chatId": { "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" } } @@ -6539,7 +6581,7 @@ "properties": { "chatId": { "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" } } @@ -6600,6 +6642,16 @@ } } } + }, + "500": { + "description": "Server failure.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } } }, "security": [ @@ -6616,7 +6668,7 @@ "properties": { "chatId": { "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" } } @@ -6628,7 +6680,7 @@ "properties": { "chatId": { "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" } } @@ -6689,6 +6741,16 @@ } } } + }, + "500": { + "description": "Server failure.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } } }, "security": [ @@ -6705,7 +6767,7 @@ "properties": { "chatId": { "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" } } @@ -6717,7 +6779,7 @@ "properties": { "chatId": { "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" } } @@ -6778,6 +6840,16 @@ } } } + }, + "500": { + "description": "Server failure.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } } }, "security": [ @@ -6794,7 +6866,7 @@ "properties": { "chatId": { "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" } } @@ -6806,7 +6878,7 @@ "properties": { "chatId": { "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" } } @@ -6867,6 +6939,16 @@ } } } + }, + "500": { + "description": "Server failure.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } } }, "security": [ @@ -6883,7 +6965,7 @@ "properties": { "chatId": { "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" } } @@ -6895,7 +6977,7 @@ "properties": { "chatId": { "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" } } @@ -6956,6 +7038,16 @@ } } } + }, + "500": { + "description": "Server failure.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } } }, "security": [ @@ -6972,7 +7064,7 @@ "properties": { "chatId": { "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" } } @@ -6984,7 +7076,7 @@ "properties": { "chatId": { "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" } } @@ -7045,6 +7137,16 @@ } } } + }, + "500": { + "description": "Server failure.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } } }, "security": [ @@ -7061,7 +7163,7 @@ "properties": { "chatId": { "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" } } @@ -7073,7 +7175,7 @@ "properties": { "chatId": { "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" } } @@ -7134,6 +7236,16 @@ } } } + }, + "500": { + "description": "Server failure.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } } }, "security": [ @@ -7150,7 +7262,7 @@ "properties": { "chatId": { "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" } } @@ -7162,7 +7274,7 @@ "properties": { "chatId": { "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" } } @@ -7223,6 +7335,16 @@ } } } + }, + "500": { + "description": "Server failure.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } } }, "security": [ @@ -7239,7 +7361,7 @@ "properties": { "chatId": { "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" } } @@ -7251,7 +7373,7 @@ "properties": { "chatId": { "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" } } @@ -7312,6 +7434,16 @@ } } } + }, + "500": { + "description": "Server failure.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } } }, "security": [ @@ -7328,7 +7460,7 @@ "properties": { "chatId": { "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" } } @@ -7340,7 +7472,7 @@ "properties": { "chatId": { "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" } } @@ -7401,6 +7533,16 @@ } } } + }, + "500": { + "description": "Server failure.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } } }, "security": [ @@ -7417,7 +7559,7 @@ "properties": { "chatId": { "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" } } @@ -7429,7 +7571,7 @@ "properties": { "chatId": { "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" } } @@ -7444,6 +7586,7 @@ "tags": [ "Message" ], + "summary": "Get message", "description": "", "parameters": [ { @@ -7490,6 +7633,16 @@ } } } + }, + "500": { + "description": "Server failure.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } } }, "security": [ @@ -7506,12 +7659,12 @@ "properties": { "chatId": { "type": "string", - "description": "The Chat id which contains the message", + "description": "The chat id which contains the message", "example": "6281288888888@c.us" }, "messageId": { "type": "string", - "description": "Unique whatsApp identifier for the message", + "description": "Unique WhatsApp ID for the message", "example": "ABCDEF999999999" } } @@ -7523,12 +7676,12 @@ "properties": { "chatId": { "type": "string", - "description": "The Chat id which contains the message", + "description": "The chat id which contains the message", "example": "6281288888888@c.us" }, "messageId": { "type": "string", - "description": "Unique whatsApp identifier for the message", + "description": "Unique WhatsApp ID for the message", "example": "ABCDEF999999999" } } @@ -7543,6 +7696,7 @@ "tags": [ "Message" ], + "summary": "Delete a message from the chat", "description": "", "parameters": [ { @@ -7589,6 +7743,16 @@ } } } + }, + "500": { + "description": "Server failure.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } } }, "security": [ @@ -7605,13 +7769,18 @@ "properties": { "chatId": { "type": "string", - "description": "The Chat id which contains the message", + "description": "The chat id which contains the message", "example": "6281288888888@c.us" }, "messageId": { "type": "string", - "description": "Unique whatsApp identifier for the message", + "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 } } } @@ -7622,13 +7791,18 @@ "properties": { "chatId": { "type": "string", - "description": "The Chat id which contains the message", + "description": "The chat id which contains the message", "example": "6281288888888@c.us" }, "messageId": { "type": "string", - "description": "Unique whatsApp identifier for the message", + "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 } } } @@ -7642,6 +7816,7 @@ "tags": [ "Message" ], + "summary": "Download attached message media", "description": "", "parameters": [ { @@ -7688,6 +7863,16 @@ } } } + }, + "500": { + "description": "Server failure.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } } }, "security": [ @@ -7704,12 +7889,12 @@ "properties": { "chatId": { "type": "string", - "description": "The Chat id which contains the message", + "description": "The chat id which contains the message", "example": "6281288888888@c.us" }, "messageId": { "type": "string", - "description": "Unique whatsApp identifier for the message", + "description": "Unique WhatsApp ID for the message", "example": "ABCDEF999999999" } } @@ -7721,12 +7906,12 @@ "properties": { "chatId": { "type": "string", - "description": "The Chat id which contains the message", + "description": "The chat id which contains the message", "example": "6281288888888@c.us" }, "messageId": { "type": "string", - "description": "Unique whatsApp identifier for the message", + "description": "Unique WhatsApp ID for the message", "example": "ABCDEF999999999" } } @@ -7741,6 +7926,7 @@ "tags": [ "Message" ], + "summary": "Delete a message from the chat", "description": "", "parameters": [ { @@ -7787,6 +7973,16 @@ } } } + }, + "500": { + "description": "Server failure.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } } }, "security": [ @@ -7803,13 +7999,18 @@ "properties": { "chatId": { "type": "string", - "description": "The Chat id which contains the message", + "description": "The chat id which contains the message", "example": "6281288888888@c.us" }, "messageId": { "type": "string", - "description": "Unique whatsApp identifier for the message", + "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" } } } @@ -7820,13 +8021,18 @@ "properties": { "chatId": { "type": "string", - "description": "The Chat id which contains the message", + "description": "The chat id which contains the message", "example": "6281288888888@c.us" }, "messageId": { "type": "string", - "description": "Unique whatsApp identifier for the message", + "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" } } } @@ -7840,7 +8046,8 @@ "tags": [ "Message" ], - "description": "", + "summary": "Get information about message delivery status", + "description": "May return null if the message does not exist or is not sent by you.", "parameters": [ { "name": "sessionId", @@ -7886,6 +8093,16 @@ } } } + }, + "500": { + "description": "Server failure.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } } }, "security": [ @@ -7902,12 +8119,12 @@ "properties": { "chatId": { "type": "string", - "description": "The Chat id which contains the message", + "description": "The chat id which contains the message", "example": "6281288888888@c.us" }, "messageId": { "type": "string", - "description": "Unique whatsApp identifier for the message", + "description": "Unique WhatsApp ID for the message", "example": "ABCDEF999999999" } } @@ -7919,12 +8136,12 @@ "properties": { "chatId": { "type": "string", - "description": "The Chat id which contains the message", + "description": "The chat id which contains the message", "example": "6281288888888@c.us" }, "messageId": { "type": "string", - "description": "Unique whatsApp identifier for the message", + "description": "Unique WhatsApp ID for the message", "example": "ABCDEF999999999" } } @@ -7939,6 +8156,7 @@ "tags": [ "Message" ], + "summary": "Get the contacts mentioned", "description": "", "parameters": [ { @@ -7985,6 +8203,16 @@ } } } + }, + "500": { + "description": "Server failure.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } } }, "security": [ @@ -8001,12 +8229,12 @@ "properties": { "chatId": { "type": "string", - "description": "The Chat id which contains the message", + "description": "The chat id which contains the message", "example": "6281288888888@c.us" }, "messageId": { "type": "string", - "description": "Unique whatsApp identifier for the message", + "description": "Unique WhatsApp ID for the message", "example": "ABCDEF999999999" } } @@ -8018,12 +8246,12 @@ "properties": { "chatId": { "type": "string", - "description": "The Chat id which contains the message", + "description": "The chat id which contains the message", "example": "6281288888888@c.us" }, "messageId": { "type": "string", - "description": "Unique whatsApp identifier for the message", + "description": "Unique WhatsApp ID for the message", "example": "ABCDEF999999999" } } @@ -8038,6 +8266,7 @@ "tags": [ "Message" ], + "summary": "Get the order details", "description": "", "parameters": [ { @@ -8084,6 +8313,16 @@ } } } + }, + "500": { + "description": "Server failure.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } } }, "security": [ @@ -8100,12 +8339,12 @@ "properties": { "chatId": { "type": "string", - "description": "The Chat id which contains the message", + "description": "The chat id which contains the message", "example": "6281288888888@c.us" }, "messageId": { "type": "string", - "description": "Unique whatsApp identifier for the message", + "description": "Unique WhatsApp ID for the message", "example": "ABCDEF999999999" } } @@ -8117,12 +8356,12 @@ "properties": { "chatId": { "type": "string", - "description": "The Chat id which contains the message", + "description": "The chat id which contains the message", "example": "6281288888888@c.us" }, "messageId": { "type": "string", - "description": "Unique whatsApp identifier for the message", + "description": "Unique WhatsApp ID for the message", "example": "ABCDEF999999999" } } @@ -8137,6 +8376,7 @@ "tags": [ "Message" ], + "summary": "Get the payment details", "description": "", "parameters": [ { @@ -8183,6 +8423,16 @@ } } } + }, + "500": { + "description": "Server failure.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } } }, "security": [ @@ -8199,12 +8449,12 @@ "properties": { "chatId": { "type": "string", - "description": "The Chat id which contains the message", + "description": "The chat id which contains the message", "example": "6281288888888@c.us" }, "messageId": { "type": "string", - "description": "Unique whatsApp identifier for the message", + "description": "Unique WhatsApp ID for the message", "example": "ABCDEF999999999" } } @@ -8216,12 +8466,12 @@ "properties": { "chatId": { "type": "string", - "description": "The Chat id which contains the message", + "description": "The chat id which contains the message", "example": "6281288888888@c.us" }, "messageId": { "type": "string", - "description": "Unique whatsApp identifier for the message", + "description": "Unique WhatsApp ID for the message", "example": "ABCDEF999999999" } } @@ -8236,6 +8486,7 @@ "tags": [ "Message" ], + "summary": "Get the quoted message", "description": "", "parameters": [ { @@ -8282,6 +8533,16 @@ } } } + }, + "500": { + "description": "Server failure.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } } }, "security": [ @@ -8298,12 +8559,12 @@ "properties": { "chatId": { "type": "string", - "description": "The Chat id which contains the message", + "description": "The chat id which contains the message", "example": "6281288888888@c.us" }, "messageId": { "type": "string", - "description": "Unique whatsApp identifier for the message", + "description": "Unique WhatsApp ID for the message", "example": "ABCDEF999999999" } } @@ -8315,12 +8576,12 @@ "properties": { "chatId": { "type": "string", - "description": "The Chat id which contains the message", + "description": "The chat id which contains the message", "example": "6281288888888@c.us" }, "messageId": { "type": "string", - "description": "Unique whatsApp identifier for the message", + "description": "Unique WhatsApp ID for the message", "example": "ABCDEF999999999" } } @@ -8335,6 +8596,7 @@ "tags": [ "Message" ], + "summary": "React with an emoji", "description": "", "parameters": [ { @@ -8381,6 +8643,16 @@ } } } + }, + "500": { + "description": "Server failure.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } } }, "security": [ @@ -8397,13 +8669,18 @@ "properties": { "chatId": { "type": "string", - "description": "The Chat id which contains the message", + "description": "The chat id which contains the message", "example": "6281288888888@c.us" }, "messageId": { "type": "string", - "description": "Unique whatsApp identifier for the message", + "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": "👍" } } } @@ -8414,13 +8691,18 @@ "properties": { "chatId": { "type": "string", - "description": "The Chat id which contains the message", + "description": "The chat id which contains the message", "example": "6281288888888@c.us" }, "messageId": { "type": "string", - "description": "Unique whatsApp identifier for the message", + "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": "👍" } } } @@ -8434,6 +8716,7 @@ "tags": [ "Message" ], + "summary": "Send a message as a reply", "description": "", "parameters": [ { @@ -8480,6 +8763,16 @@ } } } + }, + "500": { + "description": "Server failure.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } } }, "security": [ @@ -8496,30 +8789,35 @@ "properties": { "chatId": { "type": "string", - "description": "The Chat id which contains the message", + "description": "The chat id which contains the message", "example": "6281288888888@c.us" }, "messageId": { "type": "string", - "description": "Unique whatsApp identifier for the message", + "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" } } - } - }, - "application/xml": { - "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" + }, + "examples": { + "string": { + "value": { + "messageId": "3A80E857F9B44AF60C2C", + "chatId": "6281288888888@c.us", + "contentType": "string", + "content": "Reply text!" } } } @@ -8533,6 +8831,7 @@ "tags": [ "Message" ], + "summary": "Star the message", "description": "", "parameters": [ { @@ -8579,6 +8878,16 @@ } } } + }, + "500": { + "description": "Server failure.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } } }, "security": [ @@ -8595,12 +8904,12 @@ "properties": { "chatId": { "type": "string", - "description": "The Chat id which contains the message", + "description": "The chat id which contains the message", "example": "6281288888888@c.us" }, "messageId": { "type": "string", - "description": "Unique whatsApp identifier for the message", + "description": "Unique WhatsApp ID for the message", "example": "ABCDEF999999999" } } @@ -8612,12 +8921,12 @@ "properties": { "chatId": { "type": "string", - "description": "The Chat id which contains the message", + "description": "The chat id which contains the message", "example": "6281288888888@c.us" }, "messageId": { "type": "string", - "description": "Unique whatsApp identifier for the message", + "description": "Unique WhatsApp ID for the message", "example": "ABCDEF999999999" } } @@ -8632,6 +8941,7 @@ "tags": [ "Message" ], + "summary": "Unstar the message", "description": "", "parameters": [ { @@ -8678,6 +8988,16 @@ } } } + }, + "500": { + "description": "Server failure.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } } }, "security": [ @@ -8694,12 +9014,12 @@ "properties": { "chatId": { "type": "string", - "description": "The Chat id which contains the message", + "description": "The chat id which contains the message", "example": "6281288888888@c.us" }, "messageId": { "type": "string", - "description": "Unique whatsApp identifier for the message", + "description": "Unique WhatsApp ID for the message", "example": "ABCDEF999999999" } } @@ -8711,12 +9031,468 @@ "properties": { "chatId": { "type": "string", - "description": "The Chat id which contains the message", + "description": "The chat id which contains the message", "example": "6281288888888@c.us" }, "messageId": { "type": "string", - "description": "Unique whatsApp identifier for the message", + "description": "Unique WhatsApp ID for the message", + "example": "ABCDEF999999999" + } + } + } + } + } + } + } + }, + "/message/getReactions/{sessionId}": { + "post": { + "tags": [ + "Message" + ], + "summary": "Get the reactions associated", + "description": "", + "parameters": [ + { + "name": "sessionId", + "in": "path", + "required": true, + "schema": { + "type": "string" + }, + "description": "Unique identifier for the session (alphanumeric and - allowed)", + "example": "f8377d8d-a589-4242-9ba6-9486a04ef80c" + } + ], + "responses": { + "200": { + "description": "OK" + }, + "403": { + "description": "Forbidden.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ForbiddenResponse" + } + } + } + }, + "404": { + "description": "Not Found.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/NotFoundResponse" + } + } + } + }, + "422": { + "description": "Unprocessable Entity.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } + }, + "500": { + "description": "Server failure.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } + } + }, + "security": [ + { + "apiKeyAuth": [] + } + ], + "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 ID for the message", + "example": "ABCDEF999999999" + } + } + } + }, + "application/xml": { + "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 ID for the message", + "example": "ABCDEF999999999" + } + } + } + } + } + } + } + }, + "/message/getGroupMentions/{sessionId}": { + "post": { + "tags": [ + "Message" + ], + "summary": "Get groups mentioned in this message", + "description": "", + "parameters": [ + { + "name": "sessionId", + "in": "path", + "required": true, + "schema": { + "type": "string" + }, + "description": "Unique identifier for the session (alphanumeric and - allowed)", + "example": "f8377d8d-a589-4242-9ba6-9486a04ef80c" + } + ], + "responses": { + "200": { + "description": "OK" + }, + "403": { + "description": "Forbidden.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ForbiddenResponse" + } + } + } + }, + "404": { + "description": "Not Found.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/NotFoundResponse" + } + } + } + }, + "422": { + "description": "Unprocessable Entity.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } + }, + "500": { + "description": "Server failure.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } + } + }, + "security": [ + { + "apiKeyAuth": [] + } + ], + "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 ID for the message", + "example": "ABCDEF999999999" + } + } + } + }, + "application/xml": { + "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 ID for the message", + "example": "ABCDEF999999999" + } + } + } + } + } + } + } + }, + "/message/edit/{sessionId}": { + "post": { + "tags": [ + "Message" + ], + "summary": "Edit the message", + "description": "", + "parameters": [ + { + "name": "sessionId", + "in": "path", + "required": true, + "schema": { + "type": "string" + }, + "description": "Unique identifier for the session (alphanumeric and - allowed)", + "example": "f8377d8d-a589-4242-9ba6-9486a04ef80c" + } + ], + "responses": { + "200": { + "description": "OK" + }, + "403": { + "description": "Forbidden.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ForbiddenResponse" + } + } + } + }, + "404": { + "description": "Not Found.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/NotFoundResponse" + } + } + } + }, + "422": { + "description": "Unprocessable Entity.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } + }, + "500": { + "description": "Server failure.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } + } + }, + "security": [ + { + "apiKeyAuth": [] + } + ], + "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" + }, + "content": { + "type": "string", + "description": "The content of the message" + }, + "options": { + "type": "object", + "description": "Options used when editing the message" + } + } + } + }, + "application/xml": { + "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" + } + } + } + } + } + } + } + }, + "/message/getContact/{sessionId}": { + "post": { + "tags": [ + "Message" + ], + "summary": "Get the contact", + "description": "", + "parameters": [ + { + "name": "sessionId", + "in": "path", + "required": true, + "schema": { + "type": "string" + }, + "description": "Unique identifier for the session (alphanumeric and - allowed)", + "example": "f8377d8d-a589-4242-9ba6-9486a04ef80c" + } + ], + "responses": { + "200": { + "description": "OK" + }, + "403": { + "description": "Forbidden.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ForbiddenResponse" + } + } + } + }, + "404": { + "description": "Not Found.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/NotFoundResponse" + } + } + } + }, + "422": { + "description": "Unprocessable Entity.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } + }, + "500": { + "description": "Server failure.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } + } + }, + "security": [ + { + "apiKeyAuth": [] + } + ], + "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 ID for the message", + "example": "ABCDEF999999999" + } + } + } + }, + "application/xml": { + "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 ID for the message", "example": "ABCDEF999999999" } } @@ -8731,6 +9507,7 @@ "tags": [ "Contact" ], + "summary": "Get the contact", "description": "", "parameters": [ { @@ -8777,6 +9554,16 @@ } } } + }, + "500": { + "description": "Server failure.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } } }, "security": [ @@ -8793,7 +9580,7 @@ "properties": { "contactId": { "type": "string", - "description": "Unique whatsApp identifier for the contact", + "description": "Unique WhatsApp ID for the contact", "example": "6281288888888@c.us" } } @@ -8805,7 +9592,7 @@ "properties": { "contactId": { "type": "string", - "description": "Unique whatsApp identifier for the contact", + "description": "Unique WhatsApp ID for the contact", "example": "6281288888888@c.us" } } @@ -8820,6 +9607,7 @@ "tags": [ "Contact" ], + "summary": "Block contact", "description": "", "parameters": [ { @@ -8866,6 +9654,16 @@ } } } + }, + "500": { + "description": "Server failure.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } } }, "security": [ @@ -8882,7 +9680,7 @@ "properties": { "contactId": { "type": "string", - "description": "Unique whatsApp identifier for the contact", + "description": "Unique WhatsApp ID for the contact", "example": "6281288888888@c.us" } } @@ -8894,7 +9692,7 @@ "properties": { "contactId": { "type": "string", - "description": "Unique whatsApp identifier for the contact", + "description": "Unique WhatsApp ID for the contact", "example": "6281288888888@c.us" } } @@ -8909,7 +9707,8 @@ "tags": [ "Contact" ], - "description": "", + "summary": "Get the contact's current info", + "description": "Get the Contact's current 'about' info. Returns null if you don't have permission to read their status.", "parameters": [ { "name": "sessionId", @@ -8955,6 +9754,16 @@ } } } + }, + "500": { + "description": "Server failure.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } } }, "security": [ @@ -8971,7 +9780,7 @@ "properties": { "contactId": { "type": "string", - "description": "Unique whatsApp identifier for the contact", + "description": "Unique WhatsApp ID for the contact", "example": "6281288888888@c.us" } } @@ -8983,7 +9792,7 @@ "properties": { "contactId": { "type": "string", - "description": "Unique whatsApp identifier for the contact", + "description": "Unique WhatsApp ID for the contact", "example": "6281288888888@c.us" } } @@ -8998,7 +9807,8 @@ "tags": [ "Contact" ], - "description": "", + "summary": "Get the chat", + "description": "Get the chat that corresponds to the contact. Will return null when getting chat for currently logged in user.", "parameters": [ { "name": "sessionId", @@ -9044,6 +9854,16 @@ } } } + }, + "500": { + "description": "Server failure.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } } }, "security": [ @@ -9060,7 +9880,7 @@ "properties": { "contactId": { "type": "string", - "description": "Unique whatsApp identifier for the contact", + "description": "Unique WhatsApp ID for the contact", "example": "6281288888888@c.us" } } @@ -9072,7 +9892,7 @@ "properties": { "contactId": { "type": "string", - "description": "Unique whatsApp identifier for the contact", + "description": "Unique WhatsApp ID for the contact", "example": "6281288888888@c.us" } } @@ -9087,7 +9907,8 @@ "tags": [ "Contact" ], - "description": "", + "summary": "Unblock the contact", + "description": "Unblock the contact from WhatsApp.", "parameters": [ { "name": "sessionId", @@ -9133,6 +9954,16 @@ } } } + }, + "500": { + "description": "Server failure.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } } }, "security": [ @@ -9149,7 +9980,7 @@ "properties": { "contactId": { "type": "string", - "description": "Unique whatsApp identifier for the contact", + "description": "Unique WhatsApp ID for the contact", "example": "6281288888888@c.us" } } @@ -9161,7 +9992,7 @@ "properties": { "contactId": { "type": "string", - "description": "Unique whatsApp identifier for the contact", + "description": "Unique WhatsApp ID for the contact", "example": "6281288888888@c.us" } } @@ -9176,7 +10007,8 @@ "tags": [ "Contact" ], - "description": "", + "summary": "Get the formatted phone number", + "description": "Returns the contact's formatted phone number, (12345678901@c.us) => (+1 (234) 5678-901).", "parameters": [ { "name": "sessionId", @@ -9222,6 +10054,16 @@ } } } + }, + "500": { + "description": "Server failure.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } } }, "security": [ @@ -9238,7 +10080,7 @@ "properties": { "contactId": { "type": "string", - "description": "Unique whatsApp identifier for the contact", + "description": "Unique WhatsApp ID for the contact", "example": "6281288888888@c.us" } } @@ -9250,7 +10092,7 @@ "properties": { "contactId": { "type": "string", - "description": "Unique whatsApp identifier for the contact", + "description": "Unique WhatsApp ID for the contact", "example": "6281288888888@c.us" } } @@ -9265,7 +10107,8 @@ "tags": [ "Contact" ], - "description": "", + "summary": "Get the country code", + "description": "Returns the contact's country code, (1541859685@c.us) => (1).", "parameters": [ { "name": "sessionId", @@ -9311,6 +10154,16 @@ } } } + }, + "500": { + "description": "Server failure.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } } }, "security": [ @@ -9327,7 +10180,7 @@ "properties": { "contactId": { "type": "string", - "description": "Unique whatsApp identifier for the contact", + "description": "Unique WhatsApp ID for the contact", "example": "6281288888888@c.us" } } @@ -9339,7 +10192,7 @@ "properties": { "contactId": { "type": "string", - "description": "Unique whatsApp identifier for the contact", + "description": "Unique WhatsApp ID for the contact", "example": "6281288888888@c.us" } } @@ -9354,7 +10207,8 @@ "tags": [ "Contact" ], - "description": "", + "summary": "Get the profile picture URL", + "description": "Get the contact's profile picture URL, if privacy settings allow it.", "parameters": [ { "name": "sessionId", @@ -9400,6 +10254,16 @@ } } } + }, + "500": { + "description": "Server failure.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } } }, "security": [ @@ -9416,7 +10280,7 @@ "properties": { "contactId": { "type": "string", - "description": "Unique whatsApp identifier for the contact", + "description": "Unique WhatsApp ID for the contact", "example": "6281288888888@c.us" } } @@ -9428,7 +10292,107 @@ "properties": { "contactId": { "type": "string", - "description": "Unique whatsApp identifier for the contact", + "description": "Unique WhatsApp ID for the contact", + "example": "6281288888888@c.us" + } + } + } + } + } + } + } + }, + "/contact/getCommonGroups/{sessionId}": { + "post": { + "tags": [ + "Contact" + ], + "summary": "Get the contact's common groups", + "description": "Get the contact's common groups with you. Returns empty array if you don't have any common group.", + "parameters": [ + { + "name": "sessionId", + "in": "path", + "required": true, + "schema": { + "type": "string" + }, + "description": "Unique identifier for the session (alphanumeric and - allowed)", + "example": "f8377d8d-a589-4242-9ba6-9486a04ef80c" + } + ], + "responses": { + "200": { + "description": "OK" + }, + "403": { + "description": "Forbidden.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ForbiddenResponse" + } + } + } + }, + "404": { + "description": "Not Found.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/NotFoundResponse" + } + } + } + }, + "422": { + "description": "Unprocessable Entity.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } + }, + "500": { + "description": "Server failure.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } + } + }, + "security": [ + { + "apiKeyAuth": [] + } + ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "contactId": { + "type": "string", + "description": "Unique WhatsApp ID for the contact", + "example": "6281288888888@c.us" + } + } + } + }, + "application/xml": { + "schema": { + "type": "object", + "properties": { + "contactId": { + "type": "string", + "description": "Unique WhatsApp ID for the contact", "example": "6281288888888@c.us" } } @@ -9550,7 +10514,7 @@ }, "error": { "type": "string", - "example": "Some server error" + "example": "Not found error" } }, "xml": {