Skip to content
/ xmpp-clj Public
forked from zk/xmpp-clj

A lightweight clojure wrapper around the smack jabber/XMPP library

Notifications You must be signed in to change notification settings

b20n/xmpp-clj

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

xmpp-clj

xmpp-clj allows you to write simple jabber bots in idiomatic clojure by providing a lightweight wrapper around the smack library.

Lein

[xmpp-clj "0.1.0"]

Usage

Create a temporary jabber account for your bot. I've used gmail here, but there are a bunch of free providers

Create a leiningen project and cd into the project directory

lein new mybot
cd ./mybot

Add xmpp-clj to your deps (project.clj):

(defproject testxmpp "1.0.0-SNAPSHOT"
  :description "FIXME: write"
  :dependencies [[org.clojure/clojure "1.1.0"]
                 [org.clojure/clojure-contrib "1.1.0"]
                 [xmpp-clj "0.1.0"]]
  :dev-dependencies [[leiningen/lein-swank "1.2.0-SNAPSHOT"]])

Open up src/mybot/core.clj and require the xmpp lib:

(ns mybot.core
  (:require [xmpp-clj :as xmpp]))

Define your connection params:

;; Connection Info
(def connect-info {:username "testclojurebot@gmail.com"
                   :password "clojurebot12345"
                   :host "talk.google.com"
                   :domain "gmail.com"})

Add some logic, all this bot does is respond back to the sender with his/her message:

;; Important stuff
(defn handle-message [message]
  (let [body (:body message)
        from-user (:from-name message)]
    (str "Hi " from-user ", you sent me '" body "'")))


;; reload-helper allows you see changes to handle-message without restarting the bot.
(defn reload-helper [message] 
    (handle-message message))

Define the bot

(defonce my-bot (xmpp/start-bot connect-info reload-helper))

You can also stop the bot by using stop-bot

(xmpp/stop-bot my-bot)

Next, fire up your chat client, add your new buddy, and send him a message. The response should look someting like this:

me: hello chatbot

chatbot: Hi zachary.kim@gmail.com, you sent me 'hello chatbot'


Problems?

Open up an issue

License

Eclipse Public License v1.0

About

A lightweight clojure wrapper around the smack jabber/XMPP library

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Clojure 100.0%