From c43d308a2d5d2a147bb182c6e01705325ca7d74f Mon Sep 17 00:00:00 2001 From: allburov Date: Fri, 22 Mar 2024 09:11:43 +0700 Subject: [PATCH] [core] Add star unstar Fix #240 --- .../content/en/docs/how-to/engines/index.md | 33 ++++++++++--------- .../en/docs/how-to/send-messages/index.md | 27 +++++++++++++++ .../content/en/docs/overview/changelog.md | 26 +++++++++++++-- src/api/chatting.controller.ts | 9 +++++ src/core/abc/session.abc.ts | 5 +++ src/core/engines/webjs/session.webjs.core.ts | 14 ++++++++ src/structures/chatting.dto.ts | 7 ++++ 7 files changed, 102 insertions(+), 19 deletions(-) diff --git a/docs/site/content/en/docs/how-to/engines/index.md b/docs/site/content/en/docs/how-to/engines/index.md index 1142db80..d1b830b4 100644 --- a/docs/site/content/en/docs/how-to/engines/index.md +++ b/docs/site/content/en/docs/how-to/engines/index.md @@ -128,25 +128,26 @@ please [create an issue](https://github.com/devlikeapro/whatsapp-http-api/issues | **Screenshot** | | | | | `POST /api/screenshot` | ✔️ | ➖ | ✔️ | -| **Chatting** | WEBJS | NOWEB | VENOM | -|------------------------------------------------------|:-----:|:-----:|:-----:| -| `GET /api/checkNumberStatus` | ✔️ | ✔️ | ✔️ | -| `GET /api/sendContactVcard` | ➖ | ➖ | ✔️ | -| `GET /api/sendText` | ✔️ | ✔️ | ✔️ | -| `POST /api/sendText` | ✔️ | ✔️ | ✔️ | -| `POST /api/sendPoll` | ➖ | ✔️ | ➖ | -| `POST /api/sendLocation` | ✔️ | ✔️ | ✔️ | -| `POST /api/sendLinkPreview` | ➖ | ✔️ | ✔️ | +| **Chatting** | WEBJS | NOWEB | VENOM | +|-----------------------------------------------------|:-----:|:-----:|:-----:| +| `GET /api/checkNumberStatus` | ✔️ | ✔️ | ✔️ | +| `GET /api/sendContactVcard` | ➖ | ➖ | ✔️ | +| `GET /api/sendText` | ✔️ | ✔️ | ✔️ | +| `POST /api/sendText` | ✔️ | ✔️ | ✔️ | +| `POST /api/sendPoll` | ➖ | ✔️ | ➖ | +| `POST /api/sendLocation` | ✔️ | ✔️ | ✔️ | +| `POST /api/sendLinkPreview` | ➖ | ✔️ | ✔️ | | `POST /api/sendImage` ![](/images/versions/plus.png) | ✔️ | ✔️ | ✔️ | -| `POST /api/sendFile` ![](/images/versions/plus.png) | ✔️ | ✔️ | ✔️ | +| `POST /api/sendFile` ![](/images/versions/plus.png) | ✔️ | ✔️ | ✔️ | | `POST /api/sendVoice` ![](/images/versions/plus.png) | ✔️ | ✔️ | ✔️ | | `POST /api/sendVideo` ![](/images/versions/plus.png) | ✔️ | ✔️ | ➖ | -| `POST /api/reply` | ✔️ | ✔️ | ✔️ | -| `POST /api/sendSeen` | ✔️ | ✔️ | ✔️ | -| `POST /api/startTyping` | ✔️ | ✔️ | ✔️ | -| `POST /api/stopTyping` | ✔️ | ✔️ | ➖ | -| `POST /api/reaction` | ✔️ | ✔️ | ➖ | -| `GET /api/messages` | ✔️ | ➖ | ✔️ | +| `POST /api/reply` | ✔️ | ✔️ | ✔️ | +| `POST /api/sendSeen` | ✔️ | ✔️ | ✔️ | +| `POST /api/startTyping` | ✔️ | ✔️ | ✔️ | +| `POST /api/stopTyping` | ✔️ | ✔️ | ➖ | +| `POST /api/reaction` | ✔️ | ✔️ | ➖ | +| `POST /api/star` | ✔️ | ✔️ | ➖ | +| `GET /api/messages` | ✔️ | ➖ | ✔️ | | | WEBJS | NOWEB | VENOM | |-------------------------------------------------------------------|:-----:|:-----:|:-----:| diff --git a/docs/site/content/en/docs/how-to/send-messages/index.md b/docs/site/content/en/docs/how-to/send-messages/index.md index cb74ee72..7a3ef156 100644 --- a/docs/site/content/en/docs/how-to/send-messages/index.md +++ b/docs/site/content/en/docs/how-to/send-messages/index.md @@ -116,6 +116,33 @@ To remove reaction from a message - send empty string in the reaction request. } ``` +### Star and unstar message +Use `PUT /api/star` method to star or unstar a message. + +{{< alert icon="👉" text="Star API uses PUT, not POST request! Please make sure you send right request." />}} + +**Star:** +```json +{ + "messageId": "false_71111111111@c.us_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", + "chatId": "71111111111@c.us", + "star": true, + "session": "default" +} +``` + +**Unstar:** +```json +{ + "messageId": "false_71111111111@c.us_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", + "chatId": "71111111111@c.us", + "star": false, + "session": "default" +} +``` + + + ### Send image ![](/images/versions/plus.png) Use `POST /api/sendImage` to send images. diff --git a/docs/site/content/en/docs/overview/changelog.md b/docs/site/content/en/docs/overview/changelog.md index 8a68f08c..d5617333 100644 --- a/docs/site/content/en/docs/overview/changelog.md +++ b/docs/site/content/en/docs/overview/changelog.md @@ -20,9 +20,29 @@ If you wish to get and read Release Notes - read them on one of our platforms, * You even can **subscribe to get new updates** there! ## 2024.3 -- Add [message.reaction]({{< relref "/docs/how-to/webhooks#messagereaction" >}}) webhook in **WEBJS** and **NOWEB** engines ([#275](https://github.com/devlikeapro/whatsapp-http-api/issues/275)). - - **NOWEB** engine note - reactions were sent in `'message'` and `'message.any'` events, not it's available **only** in `'message.reaction'`! -- Add security settings [Security - who can send messages]({{< relref "/docs/how-to/groups##security---who-can-send-messages" >}}) `PUT /api/{session}/groups/{groupId}/settings/security/messages-admin-only` ([#274](https://github.com/devlikeapro/whatsapp-http-api/issues/274)) +### 🎉 New + +---- + +- Add `message.reaction` webhook in **WEBJS** and **NOWEB** engines + - Read more about [message.reaction]({{< relref "/docs/how-to/webhooks#messagereaction" >}}) event + - Issue: [#275](https://github.com/devlikeapro/whatsapp-http-api/issues/275) + +**NOWEB** engine note - reactions were sent in `'message'` and `'message.any'` events, not it's available **only** in `'message.reaction'`! + +---- + +- Add security settings for who can send messages `PUT /api/{session}/groups/{groupId}/settings/security/messages-admin-only` + - Read [Security - who can send messages]({{< relref "/docs/how-to/groups##security---who-can-send-messages" >}}) + - Issue: [#274](https://github.com/devlikeapro/whatsapp-http-api/issues/274) + +---- + +- Add star and unstar message endpoint `PUT /api/star` + - Read [Star and unstar message]({{< relref "/docs/how-to/send-messages#star-and-unstar-message" >}}) documentation + - Issue: [#273](https://github.com/devlikeapro/whatsapp-http-api/issues/240) + +---- ### 👉 Breaking changes - **NOWEB** - reactions were sent in `'message'` and `'message.any'` events, not it's available **only** in `'message.reaction'`! diff --git a/src/api/chatting.controller.ts b/src/api/chatting.controller.ts index ff65ba56..f71eacc1 100644 --- a/src/api/chatting.controller.ts +++ b/src/api/chatting.controller.ts @@ -14,6 +14,7 @@ import { MessagePollRequest, MessageReactionRequest, MessageReplyRequest, + MessageStarRequest, MessageTextQuery, MessageTextRequest, MessageVideoRequest, @@ -157,6 +158,14 @@ export class ChattingController { return whatsapp.setReaction(request); } + @Put('/star') + @ApiOperation({ summary: 'Star or unstar a message' }) + async setStar(@Body() request: MessageStarRequest) { + const whatsapp = this.manager.getSession(request.session); + await whatsapp.setStar(request); + return; + } + @Get('/messages') @ApiOperation({ summary: 'Get messages in a chat' }) getMessages(@Query() query: GetMessageQuery) { diff --git a/src/core/abc/session.abc.ts b/src/core/abc/session.abc.ts index b4df333d..6edd2f12 100644 --- a/src/core/abc/session.abc.ts +++ b/src/core/abc/session.abc.ts @@ -15,6 +15,7 @@ import { MessagePollRequest, MessageReactionRequest, MessageReplyRequest, + MessageStarRequest, MessageTextRequest, MessageVideoRequest, MessageVoiceRequest, @@ -265,6 +266,10 @@ export abstract class WhatsappSession { abstract setReaction(request: MessageReactionRequest); + setStar(request: MessageStarRequest): Promise { + throw new NotImplementedByEngineError(); + } + /** * Chats methods */ diff --git a/src/core/engines/webjs/session.webjs.core.ts b/src/core/engines/webjs/session.webjs.core.ts index 59b8bce8..c7df5773 100644 --- a/src/core/engines/webjs/session.webjs.core.ts +++ b/src/core/engines/webjs/session.webjs.core.ts @@ -21,6 +21,7 @@ import { MessageLocationRequest, MessageReactionRequest, MessageReplyRequest, + MessageStarRequest, MessageTextRequest, MessageVoiceRequest, SendSeenRequest, @@ -292,6 +293,19 @@ export class WhatsappSessionWebJSCore extends WhatsappSession { return message.react(request.reaction); } + async setStar(request: MessageStarRequest) { + const messageId = this.deserializeId(request.messageId); + // Recreate instance to apply star + const message = new MessageInstance(this.whatsapp); + message.id = messageId; + message._data = { id: messageId }; + if (request.star) { + await message.star(); + } else { + await message.unstar(); + } + } + /** * Chats methods */ diff --git a/src/structures/chatting.dto.ts b/src/structures/chatting.dto.ts index 393f5468..07546d64 100644 --- a/src/structures/chatting.dto.ts +++ b/src/structures/chatting.dto.ts @@ -167,6 +167,13 @@ export class MessageReactionRequest extends MessageRequest { reaction: string; } +export class MessageStarRequest extends MessageRequest { + @ChatIdProperty() + chatId: string; + + star: boolean; +} + export class WANumberExistResult { numberExists: boolean; @ApiProperty({