如何使WhatsApp机器人的Java代码仅返回我的联系人作为聊天ID

时间:2019-05-09 23:14:07

标签: javascript chat chatbot

我在Java中有一个whatsapp机器人的代码。目前,只要他们说了关键字,它就会获取所有聊天ID并响应所有聊天,但是我希望用户在获得响应之前先选择加入。现在,尽管我希望它仅返回我的联系人作为聊天ID,并仅回复他们

    /**
 * Serializes a chat object
 *
 * @param rawChat Chat object
 * @returns {{}}
 */

window.WAPI._serializeChatObj = obj => {
  if (obj == undefined) {
    return null;
  }

  return Object.assign(window.WAPI._serializeRawObj(obj), {
    kind: obj.kind,
    isGroup: obj.isGroup,
    contact: obj['contact'] ? window.WAPI._serializeContactObj(obj['contact']) : null,
    groupMetadata: obj['groupMetadata'] ? window.WAPI._serializeRawObj(obj['groupMetadata']) : null,
    presence: obj['presence'] ? window.WAPI._serializeRawObj(obj['presence']) : null,
    msgs: null
  });
};

window.WAPI._serializeContactObj = obj => {
  if (obj == undefined) {
    return null;
  }

  return Object.assign(window.WAPI._serializeRawObj(obj), {
    formattedName: obj.formattedName,
    isHighLevelVerified: obj.isHighLevelVerified,
    isMe: obj.isMe,
    isMyContact: obj.isMyContact,
    isPSA: obj.isPSA,
    isUser: obj.isUser,
    isVerified: obj.isVerified,
    isWAContact: obj.isWAContact,
    profilePicThumbObj: obj.profilePicThumb ? window.WAPI._serializeProfilePicThumb(obj.profilePicThumb) : {},
    statusMute: obj.statusMute,
    msgs: null
  });
};

window.WAPI._serializeMessageObj = obj => {
  if (obj == undefined) {
    return null;
  }

  return Object.assign(window.WAPI._serializeRawObj(obj), {
    id: obj.id._serialized,
    sender: obj['senderObj'] ? window.WAPI._serializeContactObj(obj['senderObj']) : null,
    timestamp: obj['t'],
    content: obj['body'],
    isGroupMsg: obj.isGroupMsg,
    isLink: obj.isLink,
    isMMS: obj.isMMS,
    isMedia: obj.isMedia,
    isNotification: obj.isNotification,
    isPSA: obj.isPSA,
    type: obj.type,
    chat: window.WAPI._serializeChatObj(obj['chat']),
    chatId: obj.id.remote,
    quotedMsgObj: window.WAPI._serializeMessageObj(obj['_quotedMsgObj']),
    mediaData: window.WAPI._serializeRawObj(obj['mediaData'])
  });
};

window.WAPI._serializeNumberStatusObj = obj => {
  if (obj == undefined) {
    return null;
  }

  return Object.assign(
    {},
    {
      id: obj.jid,
      status: obj.status,
      isBusiness: obj.biz === true,
      canReceiveMessage: obj.status === 200
    }
  );
 };

 window.WAPI._serializeProfilePicThumb = obj => {
  if (obj == undefined) {
    return null;
  }

  return Object.assign(
    {},
    {
      eurl: obj.eurl,
      id: obj.id,
      img: obj.img,
      imgFull: obj.imgFull,
      raw: obj.raw,
      tag: obj.tag
    }
  );
};

/**
 * Fetches all chat IDs from store
 *
 * @param done Optional callback function for async execution
 * @returns {Array|*} List of chat id's
 */
window.WAPI.getAllChatIds = function (done) {
  const chatIds = window.Store.Chat.map(chat => chat.id._serialized || chat.id);

  if (done !== undefined) done(chatIds);
  return chatIds;
};

0 个答案:

没有答案