Update WhatsappDirectLine.ts

This commit is contained in:
Rodrigo Rodriguez 2019-06-23 07:03:32 -03:00 committed by GitHub
parent 065d0fa2f7
commit 013ad665d7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -171,34 +171,21 @@ export class WhatsappDirectLine extends GBService {
} }
public pollMessages(client, conversationId, from, fromName) { public pollMessages(client, conversationId, from, fromName) {
GBLog.info(`GBWhatsapp: Starting polling message for conversationId: GBLog.info(`GBWhatsapp: Starting message polling(${from}, ${conversationId}).`);
${conversationId}.`);
let task: NodeJS.Timer; const worker = async () => {
const worker = () => { try {
clearInterval(task); const response = client.Conversations.Conversations_GetActivities({
client.Conversations.Conversations_GetActivities({ conversationId: conversationId,
conversationId: conversationId, watermark: this.watermark
watermark: this.watermark
})
.then(response => {
this.watermark = response.obj.watermark;
return response.obj.activities;
})
.catch(err => {
GBLog.error(`Error calling Conversations_GetActivities on Whatsapp channel ${err.data}`);
})
.then(async activities => {
await this.printMessages(activities, conversationId, from, fromName);
})
.catch(err => {
GBLog.error(`Error calling printMessages on Whatsapp channel ${err.data}`);
}); });
task = setInterval(worker, this.pollInterval); await this.printMessages(response.obj.activities, conversationId, from, fromName);
} catch (err) {
GBLog.error(`Error calling printMessages on Whatsapp channel ${err.data}`);
}
}; };
task = setInterval(worker, this.pollInterval); setInterval(worker, this.pollInterval);
} }
public async printMessages(activities, conversationId, from, fromName) { public async printMessages(activities, conversationId, from, fromName) {