Small improvements to Mailjet-Node

This commit is contained in:
Jan Oberhauser
2020-02-14 16:56:22 -08:00
parent 202f7ada03
commit 91e5b7fde2
4 changed files with 165 additions and 119 deletions

View File

@@ -62,14 +62,14 @@ export class MailjetTrigger implements INodeType {
name: 'email.open',
value: 'open',
},
{
name: 'email.spam',
value: 'spam',
},
{
name: 'email.sent',
value: 'sent',
},
{
name: 'email.spam',
value: 'spam',
},
{
name: 'email.unsub',
value: 'unsub',
@@ -85,17 +85,22 @@ export class MailjetTrigger implements INodeType {
webhookMethods = {
default: {
async checkExists(this: IHookFunctions): Promise<boolean> {
const webhookData = this.getWorkflowStaticData('node');
if (webhookData.webhookId === undefined) {
return false;
const endpoint = `/v3/rest/eventcallbackurl`;
const responseData = await mailjetApiRequest.call(this, 'GET', endpoint);
const event = this.getNodeParameter('event') as string;
const webhookUrl = this.getNodeWebhookUrl('default');
for (const webhook of responseData.Data) {
if (webhook.EventType === event && webhook.Url === webhookUrl) {
// Set webhook-id to be sure that it can be deleted
const webhookData = this.getWorkflowStaticData('node');
webhookData.webhookId = webhook.ID as string;
return true;
}
}
const endpoint = `/v3/rest/eventcallbackurl/${webhookData.webhookId}`;
try {
await mailjetApiRequest.call(this, 'GET', endpoint);
} catch (e) {
return false;
}
return true;
return false;
},
async create(this: IHookFunctions): Promise<boolean> {
const webhookUrl = this.getNodeWebhookUrl('default');