emacs-appointment-notifications-via-xmpp.html 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. title: Emacs appointment notifications via XMPP
  2. date: 2010-11-21 16:11
  3. tags: orgmode, xmpp, foss, emacs
  4. author: Christine Lemmer-Webber
  5. slug: emacs-appointment-notifications-via-xmpp
  6. ---
  7. <p>
  8. Since I've started using Emacs' appointment notifications with
  9. orgmode, I've wished that I could get notifications via XMPP. I
  10. think it's the most sensible system to use; I have it running on
  11. both my desktop, my phone, and my laptop, and the whole issue of
  12. "figuring out which device to send this notification to" has already
  13. been evaluated and solved by the XMPP community long long ago (back
  14. when everyone called XMPP Jabber, even ;)).
  15. </p>
  16. <p>
  17. I initially thought I'd use a
  18. <a href="https://github.com/fritzy/SleekXMPP/wiki">SleekXMPP</a>
  19. bot connected to emacs via D-Bus, but then I decided that maybe I would
  20. eventually want to add more commands to this that integrated more
  21. closely with emacs, so maybe I should use emacs lisp directly. I
  22. had heard of
  23. <a href="http://www.emacswiki.org/cgi-bin/wiki/JabberEl">Jabber.el</a>
  24. but thought that it was mainly aimed at users who want a client, and
  25. that writing a bot in it would end up cluttering up my emacs with
  26. extra UI stuff I don't want. Then I was pointed at
  27. <a href="http://www.emacswiki.org/emacs/steersman.el">Steersman.el</a>,
  28. and that seemed like a cleanly written bot, so I decided to give it
  29. a shot.
  30. </p>
  31. <p>
  32. I was running a newer version of JabberEl than the copy of
  33. Steersman's code I looked at, so it took a little bit to figure out
  34. how to adjust for the multi-account code, but once I did that the
  35. implementation happened fairly quickly. Here's the relevant code:
  36. </p>
  37. <p>
  38. <pre>;; Copyright (C) 2010 Chris Lemmer-Webber
  39. ;; This program is free software; you can redistribute it and/or modify
  40. ;; it under the terms of the GNU General Public License as published by
  41. ;; the Free Software Foundation; either version 3, or (at your option)
  42. ;; any later version.
  43. ;;
  44. ;; This program is distributed in the hope that it will be useful,
  45. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  46. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  47. ;; GNU General Public License for more details.
  48. (require 'jabber)
  49. (load-file "~/.emacs.d/emacs-jabberbot-login.el")
  50. (defun botler-&gt;appt-message-me (min-to-app new-time appt-msg)
  51. "Message me about an upcoming appointment."
  52. (let ((message-body
  53. (format "Appointment %s: %s%s"
  54. (if (string-equal "0" min-to-app) "now"
  55. (format "in %s minute%s" min-to-app
  56. (if (string-equal "1" min-to-app) "" "s")))
  57. new-time appt-msg)))
  58. (jabber-send-sexp
  59. (jabber-find-connection "thisbot@example.org")
  60. `(message ((to . "sendto@example.org")
  61. (type . "normal"))
  62. (body () ,message-body)))))
  63. ; I don't care when people come online to my bot's roster.
  64. (setq jabber-alert-presence-hooks nil)
  65. (setq appt-display-format 'window)
  66. (setq appt-disp-window-function 'botler-&gt;appt-message-me)
  67. (setq appt-delete-window-function (lambda ()))</pre></p>
  68. <p>
  69. Adjust "thisbot@example.org" with your bot's JID and
  70. "sendto@example.org" with who you want to send messages to. You can
  71. replace emacs-jabber-bot-login.el with whatevever you want to login
  72. with, but you probably want to setq jabber-account-list and then run
  73. (jabber-connect-all). Note that if you're connecting with a
  74. self-signed cert with Jabber.el you'll need to do:
  75. </p>
  76. <p><pre>(setq starttls-extra-arguments '("--insecure"))
  77. (setq starttls-use-gnutls t)</pre></p>
  78. <p>
  79. I haven't yet figured how to whitelist my own self-signed cert yet,
  80. and passing in --insecure makes me feel like a monster, but it works
  81. for now. Maybe it's about time I finally got my ssl cert signed for
  82. dustycloud.org.
  83. </p>
  84. <p>
  85. Anyway! It works, and I've been successfully getting appointment
  86. messages from my emacs session over IM for the last week, and it's
  87. pretty great. Next up, configuring things so that I can retrieve my
  88. agenda over IM when I request it and be able to IM myself new tasks
  89. and events.
  90. </p>