Emacs Lisp: kdeconnect-sms-send or sending SMS straight from Emacs

Emacs Lisp: kdeconnect-sms-send or sending SMS straight from Emacs

kdeconnect is great program to connect various mobile devices and computers. It works well between mobile devices as well. Emacs as text editor functions as advanced programmable framework that allows users to do just anything with programming language Emacs Lisp allows. Example is that Emacs could be converted into SMS gateway for marketing purposes. Only the concepts are described here.

There are several ways how one can send SMS from computer to running and connected Replicant or LineageOS or Android or other similar devices. There are other mobile operating system that are free software and they may have different options to send SMS programmatically.

I am here presenting few solutions that I am using with success since quite a lot of time.

;;; Mixture of these functions only show that 
;;; I am not yet clear if I should quote Android 
;;; shell commands with double quotes or single quotes.

(defun termux/escape-double-quotes (s)
  "Escapes double quotes"
  (replace-regexp-in-string "\"" "\\\\\"" s))
  
(defun termux/escape-quotes (s)
  "Escapes double and single quotes"
  (let* ((s (termux/escape-double-quotes s)))
    ;;(s (termux/escape-single-quotes s)))
    s))

(defun termux/send-command (command)
  "Sends command to connected Replicant device and returns the output string"
  (let* ((command (concat termux-ssh-command " -p " termux-ssh-port " " termux-ip " \"" command "\""))
     (output (shell-command-to-string command))
     (output (string-trim output)))
    output))

;;; The below example shows how ShellMS application may be used to send SMS
;;; by using Replicant or Android or LineageOS or similar mobile operating systems

(defun termux-sms-send (number text)
  "Send SMS message by using ShellMS application"
  (let* ((text (termux/escape-quotes text))
     (command (format "am startservice --user 0 -n com.android.shellms/.sendSMS -e contact %s -e msg \\\"%s\\\"" number text)))
    (termux/send-command command)))

In some countries like Uganda, or Tanzania, Kenya, people are using different numbers, sometimes two or three numbers, as expenses to call somebody on other network may be high. So people use the network of the call or SMS receiver. Emacs Lisp could then decide which prefixes belong to which network and then could choose the device appropriate to send the SMS. That would save the money and easier bond with the clients who will not feel pressure to contact the initiator on the other network.

By using these principles of connecting various devices to computer, one could understand that such could be used for SMS or Gateway purposes. Emacs Lisp is not the only example, just any programming language could be used to send SMS to connected Replicant, or Android or LineageOS devices.

In my personal case, all CRM or Customer Relationship data is held and managed through Emacs and Emacs Lisp functions, rather than through a browser or browser based software. That allows me to make quick decisions or to inform clients, partners, family by using SMS, or by initiating calls through Termux functions. At my side every SMS is saved and later I may retrieve them for review of the conversation with the person.

SMS received and sent on mobile device is exported and then imported into my database for management of customers' relations, which is named Central Files.

There exists the Emacs Lisp package kdeconnect in ELPA, but I have not used it, and I think that functions are defunct, it can be easily improved.

(defun kdeconnect-sms-send (number text)
  "Send SMS message by using KDEConnect application"
  (let* ((text (string-utils-escape-double-quotes text))
     (device "c47e5d958b455603") ;; Moto E
     (device "73fc592ea61a3a70") ;; Archos 101
     (command (format "kdeconnect-cli -d %s --send-sms \"%s\" --destination \"%s\"" device text number)))
    (message command)
    (shell-command command)))

Emacs Lisp is quite capable to serve as SMS gateway. Just imagine people entering SMS over Internet or over various other devices, such SMS being saved on server temporarily, in the queue, and Emacs Lisp computers fetching SMS and forwarding it to various numbers. Through my SMS marketing activities, I have helped my client in 2008 to earn more than 500,000 euro.

Leave Your Comment or Contact GNU.Support

Contact GNU.Support now. There is a simple rule at GNU.Support: if we can help you, we do, whenever and wherever necessary, and it's the way we've been doing business since 2002, and the only way we know


Full name:


E-mail:


Message: