Skip to content

Commit

Permalink
mailgun-js: Allow sending templates (DefinitelyTyped#35871)
Browse files Browse the repository at this point in the history
* Added 'template' support for sending messages with mailgun.

* Implemented suggested changes.

* Switched template variables to 'any' as otherwise they conflict with existing properties (like 'to' allowing 'string[]')

* Removed 'any'.
  • Loading branch information
CodeLenny authored and sandersn committed Aug 6, 2019
1 parent 13f4004 commit c58a884
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
8 changes: 7 additions & 1 deletion types/mailgun-js/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Definitions by: Sampson Oliver <https://github.com/sampsonjoliver>
// Andi Pätzold <https://github.com/andipaetzold>
// Jiri Balcar <https://github.com/JiriBalcar>
// Ryan Leonard <https://github.com/CodeLenny>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3

Expand Down Expand Up @@ -113,6 +114,11 @@ declare namespace Mailgun {
'recipient-variables'?: BatchSendRecipientVars;
}

type SendTemplateData = SendData & {
template: string;
[templateVariable: string]: string;
};

interface BatchSendRecipientVars {
[email: string]: {
first: string;
Expand Down Expand Up @@ -232,7 +238,7 @@ declare namespace Mailgun {

interface Messages {
send(
data: messages.SendData | messages.BatchData,
data: messages.SendData | messages.BatchData | messages.SendTemplateData,
callback?: (error: Error, body: messages.SendResponse) => void
): Promise<messages.SendResponse>;
}
Expand Down
8 changes: 8 additions & 0 deletions types/mailgun-js/mailgun-js-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ const arraySendData: mailgunFactory.messages.SendData = {

mailgun.messages().send(arraySendData, (err, body) => {});

const exampleSendDataWithTemplate: mailgunFactory.messages.SendTemplateData = {
to: "someone@email.com",
template: "my-template",
"v:template-variable": "foo",
};

const exampleSendDataTemplateResponse: Promise<mailgunFactory.messages.SendResponse> = mailgun.messages().send(exampleSendDataWithTemplate);

let validationResultPromise: Promise<mailgunFactory.validation.ValidateResponse>;
validationResultPromise = mailgun.validate("foo@mailgun.net");
validationResultPromise = mailgun.validate("foo@mailgun.net", true);
Expand Down

0 comments on commit c58a884

Please sign in to comment.