Update WhatsappDirectLine.ts
This commit is contained in:
parent
065d0fa2f7
commit
013ad665d7
1 changed files with 11 additions and 24 deletions
|
@ -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) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue