3

I have Integrated Google Hangout chat for node js web application.

I am able to get spaces, members in spaces, but I am not able to get Messages of space. I also referred documentation from below link

https://developers.google.com/hangouts/chat/reference/rest/v1/spaces.messages/get 

Also here is discovery document:

https://chat.googleapis.com/$discovery/rest?version=v1

As per discovery document it needs {messageId} as a parameter but I am not sure where I can find/get messageId

Please find my code below:

module.exports.getMessage = async function (req, res) {
  try {
    let jwtClient = new google.auth.JWT(
      configAuth.hangout.client_email,
      null,
      configAuth.hangout.private_key, ['https://www.googleapis.com/auth/chat.bot']);
    const chat = google.chat({ version: 'v1', auth: jwtClient });
    chat.spaces.messages.get({
      name: `spaces/${req.query.spaceId}`, // here I also tried to add "/messages" but it gives 404
    })
      .then(result => {
        return res.json({ success: true, error: false, result: result.data });
      })
      .catch(err => {
        return res.json({ success: false, error: true, result: err });

      });
  } catch (error) {
    return res.json({ success: false, error: true, message: error });
  }
}

Please give me a solution to fetch the messages. Thanks in advance.

1 Answers1

0

Issue:

I think you are only supposed to be able to retrieve messages that have been created through the API (bots are supposed to only handle messages created by themselves).

In this case, if the message has been created via spaces.messages.create, the name to provide is retrieved in the response to the referenced call (field name). Actually, all message resource is returned by this method, but the name field can be used later to update or delete the message. In any case, you should store the name of every message you create if you want to retrieve it later.

Other ways of retrieving message name:

Other than that, there are ways of getting the messageId, but they require visiting the UI, which makes it probably not workable for your situation:

  • Click the magnifying glass, search your message and get its URL, as explained here.

  • Click on Forward to inbox, which will send an email with this message, and in the email, click Open message, which will open a new tab with the message URL ().

The retrieved URL (chat.google.com/{space_type}/{space_id}/{message_id}) can be used to get the message name: spaces/{space_id}/messages/{message_id}, but probably don't constitute a workable solution for your situation.

Reference:

Iamblichus
  • 18,540
  • 2
  • 11
  • 27