landscape/desk/ted/mailchimp/send-template.hoon

70 lines
2.1 KiB
Plaintext
Raw Normal View History

2023-04-28 06:00:44 +03:00
:: Mailchimp/Send Template
:: send an email template via the Mailchimp Transactional API
::
:: > -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
++ var-json
|= [k=cord v=cord]
(pairs:enjs:format ~[['name' s+k] ['content' s+v]])
++ vars-json
|= vars=(map cord cord)
[%a (turn ~(tap by vars) |=([p=cord q=cord] (var-json p q)))]
2023-04-28 06:00:44 +03:00
++ api-post
|= [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
%- 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)]
:: 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
:~
['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']])]]
:- 'merge_vars'
[%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
template-name=tape
vars=(map cord cord)
2023-04-28 06:00:44 +03:00
==
=/ args !<((unit arg-mold) arg)
?~ args
(pure:m !>(~))
;< ~ 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
--