Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat: Added WPP.chat.keepMessage function * fix: Typos fix * fix: Fixed imports
- Loading branch information
1 parent
576750a
commit 77298e1
Showing
6 changed files
with
137 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/*! | ||
* Copyright 2023 WPPConnect Team | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { iAmAdmin } from '../../group'; | ||
import { WPPError } from '../../util'; | ||
import { MsgKey, MsgModel } from '../../whatsapp'; | ||
import { KIC_ENTRY_POINT_TYPE } from '../../whatsapp/enums'; | ||
import { | ||
keepMessage as KeepMessage, | ||
undoKeepMessage, | ||
} from '../../whatsapp/functions'; | ||
import { getMessageById } from './getMessageById'; | ||
|
||
/** | ||
* Keep or unkeep a message in a group chat with expiration | ||
* | ||
* @example | ||
* ```javascript | ||
* // To keep a message in chat | ||
* WPP.chat.keepMessage('true_[number]@c.us_ABCDEF', true); | ||
* | ||
* // To unkeep a message in chat | ||
* WPP.chat.keepMessage('true_[number]@c.us_ABCDEF', false); | ||
* ``` | ||
* @category Chat | ||
*/ | ||
export async function keepMessage( | ||
msgId: string | MsgKey, | ||
value = true | ||
): Promise<MsgModel> { | ||
const msg = await getMessageById(msgId); | ||
if (!(await iAmAdmin(msg.id.remote))) { | ||
throw new WPPError('you_not_group_admin', 'You is not a group admin'); | ||
} else if (msg.isExpired()) { | ||
throw new WPPError('msg_expired', 'This message has expired'); | ||
} else if (value) { | ||
await KeepMessage(msg, KIC_ENTRY_POINT_TYPE.CHAT); | ||
return await getMessageById(msgId); | ||
} else { | ||
await undoKeepMessage( | ||
msg, | ||
{ deleteExpired: true }, | ||
KIC_ENTRY_POINT_TYPE.CHAT | ||
); | ||
return await getMessageById(msgId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/*! | ||
* Copyright 2023 WPPConnect Team | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { exportModule } from '../exportModule'; | ||
|
||
/** | ||
* @whatsapp 982015 | ||
*/ | ||
export declare enum KIC_ENTRY_POINT_TYPE { | ||
CHAT_INFO = 1, | ||
SEARCH = 2, | ||
CHAT = 3, | ||
MEDIA = 4, | ||
DOCS = 5, | ||
LINKS = 6, | ||
} | ||
|
||
exportModule( | ||
exports, | ||
{ | ||
KIC_ENTRY_POINT_TYPE: 'KIC_ENTRY_POINT_TYPE', | ||
}, | ||
(m) => m.KIC_ENTRY_POINT_TYPE | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/*! | ||
* Copyright 2023 WPPConnect Team | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { MsgModel } from '..'; | ||
import { exportModule } from '../exportModule'; | ||
|
||
/** | ||
* @whatsapp 170235 | ||
*/ | ||
export declare function keepMessage(msg: MsgModel, t: number): Promise<any>; | ||
export declare function undoKeepMessage( | ||
msg: MsgModel, | ||
options: { deleteExpired: boolean }, | ||
n: number | ||
): Promise<any>; | ||
|
||
exportModule( | ||
exports, | ||
{ | ||
keepMessage: 'keepMessage', | ||
undoKeepMessage: 'undoKeepMessage', | ||
}, | ||
(m) => m.keepMessage | ||
); |