summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--smsmatrix.scm37
1 files changed, 36 insertions, 1 deletions
diff --git a/smsmatrix.scm b/smsmatrix.scm
index 61d6a8a..008184e 100644
--- a/smsmatrix.scm
+++ b/smsmatrix.scm
@@ -37,7 +37,7 @@
(module smsmatrix
(smsmatrix-username smsmatrix-password
get-credits get-rate carrier-name message-status call-with-csv-report
- send-sms)
+ send-sms send-fax)
(import chicken scheme)
@@ -277,4 +277,39 @@
entry))
res))))
+;; The fax API is undocumented except for a Perl example and unsupported
+(define (send-fax recipients filename #!key
+ username password group (error-on-failure #t))
+ (let-auth 'send-fax username password
+ (let* ((recipient-type (if group 'group 'phone)) ;; TODO: test if group works for faxes
+ (recipients (if (string? recipients) ;; TODO: Check if multi-recipients works
+ recipients
+ (string-intersperse recipients ",")))
+ (res (api-request 'send-fax fax-uri
+ `((username . ,username)
+ (password . ,password)
+ (,recipient-type . ,recipients)
+ (file file: ,filename filename: ,filename
+ headers: ((content-type application/pdf))))
+ 'pin '(id statuscode statustxt timestamp))))
+ (print res)
+ ;; Check for errors in phone number recipients if it was asked for
+ (when error-on-failure
+ (for-each (lambda (entry)
+ (let ((status (alist-ref 'statuscode entry))
+ (status-text (alist-ref 'statustxt entry))
+ (pin (alist-ref 'pin entry)))
+ (error-on-bad-result-code
+ 'send-fax status status-text pin)))
+ res))
+ (map (lambda (entry)
+ (map (lambda (key/value)
+ (let ((key (car key/value))
+ (value (cdr key/value)))
+ (case key
+ ((statuscode timestamp) (cons key (string->number value)))
+ (else key/value))))
+ entry))
+ res))))
+
) \ No newline at end of file