Skip to content

Commit

Permalink
feat: Added support for send message to Meta AI
Browse files Browse the repository at this point in the history
  • Loading branch information
icleitoncosta committed Oct 29, 2024
1 parent 664e982 commit e15802b
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/chat/functions/prepareRawMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,18 @@
import { assertWid } from '../../assert';
import { getParticipants } from '../../group';
import { WPPError } from '../../util';
import { ChatModel, MsgKey, MsgModel, UserPrefs, Wid } from '../../whatsapp';
import {
BotProfileStore,
ChatModel,
MsgKey,
MsgModel,
UserPrefs,
Wid,
} from '../../whatsapp';
import { ACK } from '../../whatsapp/enums';
import {
canReplyMsg,
genBotMsgSecretFromMsgSecret,
getEphemeralFields,
unixTime,
} from '../../whatsapp/functions';
Expand Down Expand Up @@ -74,6 +82,18 @@ export async function prepareRawMessage<T extends RawMessage>(
...message,
};
}
/**
* Adding fields for Chats with bots
*/
if (chat.id?.isBot()) {
message = {
...message,
messageSecret: await genBotMsgSecretFromMsgSecret(
crypto.getRandomValues(new Uint8Array(32))
),
botPersonaId: BotProfileStore.get(chat.id?.toString())!.personaId,
};
}

if (options.messageId) {
if (typeof options.messageId === 'string') {
Expand Down
30 changes: 30 additions & 0 deletions src/whatsapp/functions/genBotMsgSecretFromMsgSecret.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*!
* Copyright 2024 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 WAWebBotMessageSecret
*/
export declare function genBotMsgSecretFromMsgSecret(a: any): Promise<any>;

exportModule(
exports,
{
genBotMsgSecretFromMsgSecret: 'genBotMsgSecretFromMsgSecret',
},
(m) => m.genBotMsgSecretFromMsgSecret
);
1 change: 1 addition & 0 deletions src/whatsapp/functions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export * from './findCommonGroups';
export * from './findFirstWebLink';
export * from './forwardMessagesToChats';
export * from './frontendFireAndForget';
export * from './genBotMsgSecretFromMsgSecret';
export * from './generateVideoThumbsAndDuration';
export * from './genLinkDeviceCodeForPhoneNumber';
export * from './genMinimalLinkPreview';
Expand Down

0 comments on commit e15802b

Please sign in to comment.