I have a GCP
Pub/Sub
subscription and topic to receive notifications from my gmail
inbox. It does indeed work and I get a message on my server when a new email arrives. The problem is that I want to get more information, such as the subject, and the content of the email. But I don't know how to do it, if I try to use:
google.gmail("v1").users.messages.get({ id: message.id, userId: 'me', format: 'full' });
But I get error 404
function listenForMessages() {
const pubSubClient = new PubSub();
try {
const subscription = pubSubClient.subscription("mysub_",);
let messageCount = 0;
const messageHandler = async message => {
console.log(`Received message ${message.id}:`);
console.log(`\tData: ${message.data}`);
const m = await google.gmail("v1").users.messages.get({ id: message.id, userId: 'me', format: 'full' });
console.log(m)
messageCount += 1;
message.ack();
};
subscription.on('message', messageHandler);
setTimeout(() => {
subscription.removeListener('message', messageHandler);
console.log(`${messageCount} message(s) received.`);
}, timeout * 1000);
} catch (error) {
console.log("MY ERROR", error)
}
}
const watchUserGmail = async () => {
const request = {
'labelIds': ['INBOX'],
'topicName': 'mytopic_',
}
google.gmail("v1").users.watch({ userId: 'me', requestBody: request })
.then((res) => res)
.catch((err) => err)
}
How can I bring that extra information into the message I get from Pub/Sub?