;;; bbdb-diamondcard.el --- Send SMS' and make phone calls from ;;; BBDB through diamondcard.us and pjsua via GNU/Emacs ;; Copyright (C) 2009 ShiroiKuma.org ;; ;; Author: ShiroiKuma.org ;; ;; Version history: ;; 0.2 2009-10-20-140000 ;; Added the phone number a call was made to or an SMS sent to ;; be logged in BBDB's contact's note field. ;; 0.1 First version, 2009-10-12-201224 ;; ;; This program is free software; you can redistribute it and/or ;; modify it under the terms of the GNU General Public License as ;; published by the Free Software Foundation; either version 3 of ;; the License, or (at your option) any later version. ;; ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; ;; You should have received a copy of the GNU General Public ;; License along with this program; if not, write to the Free ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, ;; MA 02111-1307, USA. ;;; Commentary: ;; ;;; Installation: ;; ;; Add the following to your .emacs file: ;; ;; (add-to-list 'load-path X) ;; ;; ...where X is the directory path where bbdb-diamondcard.el is stored. ;; ;; (require 'bbdb-diamondcard) ;; ;; (setq bbdb-diamondcard-pjsua-conf "absolute path to pjsua.conf file" ;; for example: ;; (setq bbdb-diamondcard-pjsua-conf "/home/shiroikuma/.pjsua/pjsua.conf") ;; ;; (setq bbdb-diamondcard-terminal "your system's terminal executable") ;; for example: ;; (setq bbdb-diamondcard-terminal "urxvt") ;;; Requirements: ;; ;; You MUST have the following setup and working: ;; (in GNU Emacs) ;; BBDB ;; ;; to send SMS ;; (in GNU Emacs) ;; diamondsms.el ;; ;; to make calls ;; (non GNU Emacs) ;; pjsua (of pjproject) ;; To call: put point on the phone number in the BBDB database and then: ;; y ;; To send and SMS: ;; x ;;; Code: ;; SMS from BBDB via diamondcard.us through diamondsms (define-key bbdb-mode-map "x" 'bbdb-diamondcard-sms) (defun bbdb-diamondcard-sms (bbdb-record text &optional date regrind) "Sends SMS and adds a note for today to the current BBDB record. Call with a prefix to specify date. BBDB-RECORD is the record to modify (default: current). TEXT is the note to add for DATE. If REGRIND is non-nil, redisplay the BBDB record." (interactive (list (bbdb-current-record t) (read-string "SMS text: ") ;; Reading date - more powerful with Planner, but we'll make do if necessary (if (featurep 'planner) (if current-prefix-arg (planner-read-date) (planner-today)) (if current-prefix-arg (read-string "Date (YYYY.MM.DD): ") (format-time-string "%Y.%m.%dT%T%z"))) t)) (let ((field (bbdb-current-field))) (if (not (eq 'phone (car field))) (error "Cannot dial %s, not a phone field" (car field))) (let ((location (aref (car (cdr field)) 0)) (name (aref (car (cdr field)) 1))) ;; Cut out +/-/ /(/) from the phone number to be dialed ;; and then send SMS (let ((number (replace-regexp-in-string "+" "" (replace-regexp-in-string "-" "" (replace-regexp-in-string " " "" (replace-regexp-in-string "(" "" (replace-regexp-in-string ")" "" name))))))) (message "Sending SMS to: %s (%s)" name location) (diamondsms-send-sms number text) (bbdb-record-putprop bbdb-record 'contact (concat date " " (format-time-string "%H:%M:%S %Z" (current-time)) ": SMS: " name ": " text "\n" (or (bbdb-record-getprop bbdb-record 'contact)))) (if regrind (save-excursion (set-buffer bbdb-buffer-name) (bbdb-redisplay-one-record bbdb-record)))))) nil) ;; Call from BBDB via diamondcard.us through pjsua (define-key bbdb-mode-map "y" 'bbdb-diamondcard-call) (defun bbdb-diamondcard-call (bbdb-record &optional date regrind) "Calls contact and adds a note for today to the current BBDB record. Call with a prefix to specify date. BBDB-RECORD is the record to modify (default: current). DATE is the date. If REGRIND is non-nil, redisplay the BBDB record." (interactive (list (bbdb-current-record t) ;; Reading date - more powerful with Planner, but we'll make do if necessary (if (featurep 'planner) (if current-prefix-arg (planner-read-date) (planner-today)) (if current-prefix-arg (read-string "Date (YYYY.MM.DD): ") (format-time-string "%Y.%m.%dT%T%z"))) t)) (let ((field (bbdb-current-field))) (if (not (eq 'phone (car field))) (error "Cannot dial %s, not a phone field" (car field))) (let ((location (aref (car (cdr field)) 0)) (name (aref (car (cdr field)) 1))) ;; Cut out +/-/ /(/) from the phone number to be dialed ;; and then send SMS (let ((number (replace-regexp-in-string "+" "" (replace-regexp-in-string "-" "" (replace-regexp-in-string " " "" (replace-regexp-in-string "(" "" (replace-regexp-in-string ")" "" name)))))) (start-time (format-time-string "%H:%M:%S %Z" (current-time)))) (message "Calling: %s (%s)" name location) (shell-command (concat bbdb-diamondcard-terminal " -e pjsua --config-file=" bbdb-diamondcard-pjsua-conf " sip:" number "@sip.diamondcard.us")) (let ((end-time (format-time-string "%H:%M:%S %Z" (current-time)))) (bbdb-record-putprop bbdb-record 'contact (concat date " " start-time " - " end-time ": Phone call: " name "\n" (or (bbdb-record-getprop bbdb-record 'contact))))) (if regrind (save-excursion (set-buffer bbdb-buffer-name) (bbdb-redisplay-one-record bbdb-record)))))) nil) (provide 'bbdb-diamondcard) ;;; bbdb-diamondcard.el ends here