diff --git a/README.md b/README.md index b0e32af..4048ea0 100644 --- a/README.md +++ b/README.md @@ -18,8 +18,8 @@ Default configuration is stored in project resources (config.edn) in [EDN format :password "Fill me up!" :host "Fill me up!" :domain "Fill me up!"} - :watchdog {:folder "scripts" - :delay 1000}} + :scripts {:folder "scripts" + :watchdog 1000}} ``` Before using, it is necessary to configure the following parameters: @@ -35,8 +35,8 @@ All parameters from this file override default config parameters. ## Development To develop Jabber command, you need to create Clojure file in the script `:folder`. -When `:delay` parameter is defined, then FS watchdog will check changes and reload scripts in runtime. -It could be useful in development mode, but you can switch if off in production mode (using `:delay` equals 0). +When `:watchdog` parameter is defined, then FS watchdog will check changes and reload scripts in runtime echo *N* milliseconds. +It could be useful in development mode, but you can switch if off in production mode (using `:watchdog` equals 0). It is necessary to follow several rules during Jabber command development: @@ -47,16 +47,36 @@ It is necessary to follow several rules during Jabber command development: * Result of the last function is the answer message, it will be sent to user. +### Script context + +Each script receives context parameters, for example: + +```clojure +{:subject nil + :from "bauer.vlad@gmail.com/gmail.3167A379" + :to "jabberjay@gmail.com" + :thread nil + :error nil + :packet-id "5A19D18217BBD43_1" + :type :chat + :from-name "bauer.vlad@gmail.com" + :body "Hi Bot" + :text "Bot"} +``` + + ### Example -This simple command always returns "Hello!", when client sends "Hi" ("HI", "hi", "hI"): +This simple command always returns "Hello, ", when client sends "Hi" ("HI", "hi", "hI"): ```clojure (ns hi) (defn init "Simple module for greating" - [msg] "Hello!") + [data] + (str "Hello, " (or (:from-name data) + (:from data)))) ``` Another example: [scripts/weather.clj](scripts/weather.clj). diff --git a/project.clj b/project.clj index 373b83a..b3c791a 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject jabberjay "0.1.1" +(defproject jabberjay "0.2.0" :description "Jabberjay - simple framework for creating Jabber bots" :url "https://github.com/vbauer/jabberjay" :license {:name "Eclipse Public License" diff --git a/resources/config.edn b/resources/config.edn index 13d47e8..c683cbc 100644 --- a/resources/config.edn +++ b/resources/config.edn @@ -3,5 +3,5 @@ :password "Fill me up!" :host "Fill me up!" :domain "Fill me up!"} - :watchdog {:folder "scripts" - :delay 1000}} + :scripts {:folder "scripts" + :watchdog 1000}} diff --git a/scripts/hi.clj b/scripts/hi.clj index e188951..37d2fb9 100644 --- a/scripts/hi.clj +++ b/scripts/hi.clj @@ -3,5 +3,5 @@ (defn init "Simple module for greating" [data] - (let [user (:from-name data)] - (str "Hello, " user))) + (str "Hello, " (or (:from-name data) + (:from data)))) diff --git a/src/jabberjay/script.clj b/src/jabberjay/script.clj index 7d92519..5fcb5a1 100644 --- a/src/jabberjay/script.clj +++ b/src/jabberjay/script.clj @@ -10,9 +10,9 @@ (def ^:private SCRIPTS (atom nil)) -(defn- conf-wd [k] ((get config/config :watchdog) k)) -(defn- conf-delay [] (conf-wd :delay)) -(defn- conf-folder [] (fs/file (conf-wd :folder))) +(defn- conf-scripts [k] ((get config/config :scripts) k)) +(defn- conf-delay [] (conf-scripts :watchdog)) +(defn- conf-folder [] (fs/file (conf-scripts :folder))) ; Internal API: Script engine