2023-04-28 06:00:44 +03:00
|
|
|
:: Mailchimp/Send Template
|
|
|
|
:: send an email template via the Mailchimp Transactional API
|
|
|
|
::
|
2023-07-19 00:33:15 +03:00
|
|
|
:: > -bark!mailchimp-send-template "[MANDRILL_API_KEY]" "someone@example.com" "template-name" vars :: vars is a (map cord cord)
|
2023-04-28 06:00:44 +03:00
|
|
|
::
|
|
|
|
/- spider
|
|
|
|
/+ *strandio
|
|
|
|
=, strand=strand:spider
|
|
|
|
=, dejs:format
|
|
|
|
=/ m (strand ,vase)
|
|
|
|
|^ ted
|
2023-05-03 19:28:44 +03:00
|
|
|
++ var-json
|
|
|
|
|= [k=cord v=cord]
|
|
|
|
(pairs:enjs:format ~[['name' s+k] ['content' s+v]])
|
2023-05-03 17:05:29 +03:00
|
|
|
++ vars-json
|
|
|
|
|= vars=(map cord cord)
|
2023-05-03 19:28:44 +03:00
|
|
|
[%a (turn ~(tap by vars) |=([p=cord q=cord] (var-json p q)))]
|
2023-04-28 06:00:44 +03:00
|
|
|
++ api-post
|
2023-05-03 17:05:29 +03:00
|
|
|
|= [api-key=tape to-email=tape template-name=tape vars=(map cord cord)]
|
2023-04-28 06:00:44 +03:00
|
|
|
%: send-request
|
|
|
|
method=%'POST'
|
|
|
|
url=url
|
|
|
|
header-list=['Content-Type'^'application/json' ~]
|
|
|
|
^= body
|
2023-05-03 17:05:29 +03:00
|
|
|
%- some
|
|
|
|
%- as-octt:mimes:html
|
2023-08-10 20:41:48 +03:00
|
|
|
%- en:json:html
|
2023-04-28 06:00:44 +03:00
|
|
|
%- pairs:enjs:format
|
|
|
|
:~ ['key' s+(crip api-key)]
|
|
|
|
['template_name' s+(crip template-name)]
|
2023-05-03 17:05:29 +03:00
|
|
|
:: null template_content is fine for now; but in the future, if we
|
|
|
|
:: need to inject complex HTML, this thread should be updated to
|
|
|
|
:: support it
|
|
|
|
['template_content' ~]
|
2023-04-28 06:00:44 +03:00
|
|
|
:- 'message'
|
|
|
|
%- pairs:enjs:format
|
2023-05-03 17:05:29 +03:00
|
|
|
:~
|
|
|
|
['merge_language' s+'handlebars']
|
2023-04-28 06:00:44 +03:00
|
|
|
:- 'to'
|
|
|
|
[%a ~[(pairs:enjs:format ~[['email' s+(crip to-email)] ['type' s+'to']])]]
|
2023-05-03 17:05:29 +03:00
|
|
|
:- 'merge_vars'
|
2023-05-03 19:28:44 +03:00
|
|
|
[%a ~[(pairs:enjs:format ~[['rcpt' s+(crip to-email)] ['vars' (vars-json vars)]])]]
|
2023-04-28 06:00:44 +03:00
|
|
|
==
|
|
|
|
==
|
|
|
|
==
|
|
|
|
++ url 'https://mandrillapp.com/api/1.0/messages/send-template'
|
|
|
|
++ ted
|
|
|
|
^- thread:spider
|
|
|
|
|= arg=vase
|
|
|
|
=/ m (strand ,vase)
|
|
|
|
^- form:m
|
|
|
|
=/ arg-mold
|
|
|
|
$: api-key=tape
|
|
|
|
to-email=tape
|
2023-05-03 17:05:29 +03:00
|
|
|
template-name=tape
|
|
|
|
vars=(map cord cord)
|
2023-04-28 06:00:44 +03:00
|
|
|
==
|
|
|
|
=/ args !<((unit arg-mold) arg)
|
|
|
|
?~ args
|
|
|
|
(pure:m !>(~))
|
2023-05-03 17:05:29 +03:00
|
|
|
;< ~ bind:m (api-post api-key.u.args to-email.u.args template-name.u.args vars.u.args)
|
2023-04-28 06:00:44 +03:00
|
|
|
;< rep=client-response:iris bind:m
|
|
|
|
take-client-response
|
|
|
|
?> ?=(%finished -.rep)
|
|
|
|
?~ full-file.rep !!
|
|
|
|
=/ body=cord q.data.u.full-file.rep
|
|
|
|
%- pure:m
|
2023-05-05 08:11:16 +03:00
|
|
|
!> `body
|
2023-04-28 06:00:44 +03:00
|
|
|
--
|