@@ -20,23 +20,111 @@ gem install wit-*.gem
2020
2121See the ` examples ` folder for examples.
2222
23+ ## API
24+
25+ ### Overview
26+
27+ ` wit-ruby ` provides a Wit class with the following methods:
28+ * ` message ` - the Wit [ message API] ( https://wit.ai/docs/http/20160330#get-intent-via-text-link )
29+ * ` converse ` - the low-level Wit [ converse API] ( https://wit.ai/docs/http/20160330#converse-link )
30+ * ` run_actions ` - a higher-level method to the Wit converse API
31+
32+ ### Wit class
33+
34+ The Wit constructor takes the following parameters:
35+ * ` access_token ` - the access token of your Wit instance
36+ * ` actions ` - the ` Hash ` with your actions
37+
38+ The ` actions ` ` Hash ` has action names as keys, and action implementations as values.
39+ Action names are symbols, and action implementations are lambda functions (not ` Proc ` ).
40+ You need to provide at least an implementation for the special actions ` :say ` , ` :merge ` and ` :error ` .
41+
42+ A minimal ` actions ` ` Hash ` looks like this:
43+ ``` ruby
44+ actions = {
45+ :say => -> (session_id, msg) {
46+ p msg
47+ },
48+ :merge => -> (context, entities) {
49+ return context
50+ },
51+ :error => -> (session_id, msg) {
52+ p ' Oops I don\' t know what to do.'
53+ },
54+ }
55+ ```
56+
57+ A custom action takes one parameter:
58+ * ` context ` - the ` Hash ` representing the session state
59+
60+ Example:
61+ ``` ruby
62+ require ' wit'
63+ client = Wit .new access_token, actions
64+ ```
65+
2366### Logging
2467
25- Default logging is to ` STDOUT ` with ` INFO ` level. Silence logger as follows.
68+ Default logging is to ` STDOUT ` with ` INFO ` level.
2669
70+ You can setup your logging level as follows:
2771``` ruby
2872Wit .logger.level = Logger ::WARN
2973```
74+ See the [ Logger class] ( http://ruby-doc.org/stdlib-2.1.0/libdoc/logger/rdoc/Logger.html ) docs for more information.
3075
31- ## API
76+ ### message
77+
78+ The Wit [ message API] ( https://wit.ai/docs/http/20160330#get-intent-via-text-link ) .
79+
80+ Takes the following parameters:
81+ * ` msg ` - the text you want Wit.ai to extract the information from
82+
83+ Example:
84+ ``` ruby
85+ resp = client.message ' what is the weather in London?'
86+ p " Yay, got Wit.ai response: #{ resp } "
87+ ```
88+
89+ ### run_actions
90+
91+ A higher-level method to the Wit converse API.
92+
93+ Takes the following parameters:
94+ * ` session_id ` - a unique identifier describing the user session
95+ * ` message ` - the text received from the user
96+ * ` context ` - the ` Hash ` representing the session state
97+ * ` max_steps ` - (optional) the maximum number of actions to execute (defaults to 5)
98+
99+ Example:
100+ ``` ruby
101+ session = ' my-user-session-42'
102+ context0 = {}
103+ context1 = client.run_actions session, ' what is the weather in London?' , context0
104+ p " The session state is now: #{ context1 } "
105+ context2 = client.run_actions session, ' and in Brussels?' , context1
106+ p " The session state is now: #{ context2 } "
107+ ```
108+
109+ ### converse
110+
111+ The low-level Wit [ converse API] ( https://wit.ai/docs/http/20160330#converse-link ) .
112+
113+ Takes the following parameters:
114+ * ` session_id ` - a unique identifier describing the user session
115+ * ` msg ` - the text received from the user
116+ * ` context ` - the ` Hash ` representing the session state
117+
118+ Example:
119+ ``` ruby
120+ resp = client.converse ' my-user-session-42' , ' what is the weather in London?' , {}
121+ p " Yay, got Wit.ai response: #{ resp } "
122+ ```
32123
33- ` wit-ruby ` provides a Wit class with the following methods:
34- * ` message ` - the Wit message API
35- * ` converse ` - the low-level Wit converse API
36- * ` run_actions ` - a higher-level method to the Wit converse API
37124
38125See the [ docs] ( https://wit.ai/docs ) for more information.
39126
127+
40128## Thanks
41129
42130Thanks to [ Justin Workman] ( http://github.com/xtagon ) for releasing a first version in October 2013. We really appreciate!
0 commit comments