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) {
GBLog.info(`GBWhatsapp: Starting polling message for conversationId:
${conversationId}.`);
GBLog.info(`GBWhatsapp: Starting message polling(${from}, ${conversationId}).`);
let task: NodeJS.Timer;
const worker = () => {
clearInterval(task);
client.Conversations.Conversations_GetActivities({
conversationId: conversationId,
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}`);
const worker = async () => {
try {
const response = client.Conversations.Conversations_GetActivities({
conversationId: conversationId,
watermark: this.watermark
});
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) {