2023-04-28 06:00:44 +03:00
|
|
|
:: Mailchimp/Send Template
|
|
|
|
:: send an email template via the Mailchimp Transactional API
|
|
|
|
::
|
2023-05-03 17:05:29 +03:00
|
|
|
:: > -bark!mailchimp-send-template "[API_KEY]" "someone@example.com" "template-name" :: TODO: how to pass in vars map?
|
2023-04-28 06:00:44 +03:00
|
|
|
::
|
|
|
|
/- spider
|
|
|
|
/+ *strandio
|
|
|
|
=, strand=strand:spider
|
|
|
|
=, dejs:format
|
|
|
|
=/ m (strand ,vase)
|
|
|
|
|^ ted
|
2023-05-03 17:05:29 +03:00
|
|
|
++ vars-json
|
|
|
|
|= vars=(map cord cord)
|
|
|
|
%- ~(rut by vars)
|
|
|
|
|= [k=cord v=cord]
|
|
|
|
[s+k s+v]
|
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-04-28 06:00:44 +03:00
|
|
|
%- en-json:html
|
|
|
|
%- 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'
|
|
|
|
:: TODO: handle passed vars
|
|
|
|
[%a ~[(pairs:enjs:format ~[['rcpt' s+(crip to-email)] ['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
|
|
|
|
?~ 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
|
|
|
|
~& rep
|
|
|
|
%- pure:m
|
|
|
|
!> [body ~]
|
|
|
|
--
|