@systemzero/baileys 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -875,16 +875,66 @@ export const makeMessagesSocket = (config) => {
875
875
  return await relayMessage(jid, rawMessage, { messageId: msgId });
876
876
  };
877
877
 
878
+ const sendMessageWrapper = async (jid, content, options = {}) => {
879
+ return await sock.sendMessage(jid, content, options);
880
+ };
881
+
878
882
  const sendPerplexity = async (jid, prompt, options = {}) => {
879
883
  try {
880
884
  const response = await axios.post('https://systemzone.store/api/post-perplexity', { q: prompt }, { timeout: 30000 });
881
885
  if (!response.data || !response.data.status) {
882
886
  throw new Error('retorno de dados invalidos.');
883
887
  }
884
- return await sock.sendMessage(jid, { text: response.data.result || 'Sem resposta.' }, options);
888
+ return await sendMessageWrapper(jid, { text: response.data.result || 'Sem resposta.' }, options);
885
889
  } catch (e) {
886
- return await sock.sendMessage(jid, { text: `Erro IA: ${e.message || e}` }, options);
890
+ return await sendMessageWrapper(jid, { text: `Erro IA: ${e.message || e}` }, options);
891
+ }
892
+ };
893
+
894
+ const sendFormulario = async (jid, textBody, flowId, screenName, dataParams = {}, buttonCta = '__localize:FLOWS_SIGN_UP_BUTTON_TITLE', flowToken = 'T0ZGRVJfU0lHTlVQ', options = {}) => {
895
+ const rawMessage = {
896
+ messageContextInfo: {
897
+ deviceListMetadata: {},
898
+ deviceListMetadataVersion: 2,
899
+ messageSecret: randomBytes(32)
900
+ },
901
+ interactiveMessage: {
902
+ body: { text: textBody },
903
+ nativeFlowMessage: {
904
+ buttons: [{
905
+ name: 'galaxy_message',
906
+ buttonParamsJson: JSON.stringify({
907
+ flow_message_version: '4',
908
+ flow_id: String(flowId),
909
+ flow_action_payload: {
910
+ screen: screenName,
911
+ data: dataParams
912
+ },
913
+ well_version: 'V700',
914
+ flow_cta: buttonCta,
915
+ flow_action: 'navigate',
916
+ flow_token: flowToken
917
+ })
918
+ }],
919
+ messageParamsJson: '{}'
920
+ }
921
+ }
922
+ };
923
+
924
+ const finalMessage = { viewOnceMessage: { message: rawMessage } };
925
+ const msgId = generateMessageIDV2(sock.user?.id);
926
+
927
+ const participantAttr = options.quoted ? {
928
+ stanzaId: options.quoted.key.id,
929
+ participant: options.quoted.sender || options.quoted.key?.participant,
930
+ quotedMessage: options.quoted.message
931
+ } : undefined;
932
+
933
+ if (participantAttr) {
934
+ finalMessage.viewOnceMessage.message.interactiveMessage.contextInfo = participantAttr;
887
935
  }
936
+
937
+ return await relayMessage(jid, finalMessage, { messageId: msgId });
888
938
  };
889
939
 
890
940
  return {
@@ -910,6 +960,7 @@ export const makeMessagesSocket = (config) => {
910
960
  makeTable,
911
961
  sendRichReels,
912
962
  sendPerplexity,
963
+ sendFormulario,
913
964
  normalizeSystem,
914
965
  sendRichText: async (remoteJid, text, quoted = null) => sendRich(remoteJid, [makeText(text)], quoted),
915
966
  sendRichCode: async (remoteJid, title, language, code, quoted = null) => {
@@ -1024,7 +1075,7 @@ export const makeMessagesSocket = (config) => {
1024
1075
 
1025
1076
  btn.buttonParamsJson = JSON.stringify(params);
1026
1077
  } catch (e) {
1027
- logger.error({ err: e }, "[System Baileys] Erro ao processar JSON de Pagamento Nativo/Flow");
1078
+ logger.error({ err: e }, "Erro ao processar JSON de Pagamento");
1028
1079
  }
1029
1080
  }
1030
1081
  return btn;
@@ -1053,7 +1104,6 @@ export const makeMessagesSocket = (config) => {
1053
1104
  rawMessage.interactiveMessage.body = { text: content.text };
1054
1105
  }
1055
1106
 
1056
- // Invólucro viewOnce exigido para renderização correta de WhatsApp Flows
1057
1107
  const finalMessage = {
1058
1108
  viewOnceMessage: {
1059
1109
  message: rawMessage
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@systemzero/baileys",
3
3
  "type": "module",
4
- "version": "1.0.1",
4
+ "version": "1.0.2",
5
5
  "description": "System-zero baileys bot",
6
6
  "keywords": [
7
7
  "whatsapp",