Commits

Peter Bex  committed 348f1ff

Implement fax API (which I haven't been able to test successfully and which isn't supported)

  • Participants
  • Parent commits f34c1ac

Comments (0)

Files changed (1)

File smsmatrix.scm

 (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)
 
                   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))))
+
 )