docs/07-replies.md in stealth-1.0.4 vs docs/07-replies.md in stealth-1.1.0.rc1

- old
+ new

@@ -1,10 +1,10 @@ --- title: Replies --- -Stealth replies can send one or more replies to a user. Reply types are dependent on the specific messaging service you're using. Each service integration will detail it's supported reply types in it's respective docs. +Stealth replies can send one or more replies to a user. The supported reply types will depend on the specific messaging service you're using. Each service integration will detail it's supported reply types in it's respective docs. However, here is a generic reply using text, delays, and suggestions. ```yml - reply_type: text @@ -20,10 +20,26 @@ suggestions: - text: "Yes" - text: "No" ``` +## Reply Variants + +By default, Stealth will look for your replies in the folder corresponding to your controller name. So, for example, if you have a `MessagesController`, Stealth will look for replies in `bot/replies/messages`. + +If you have an action named `say_hello`, it will look for a reply file named `bot/replies/messages/say_hello.yml.erb` first, and then if that is not found, it will look for `bot/replies/messages/say_hello.yml`. If neither of these files are found, Stealth will raise a `Stealth::Errors::ReplyNotFound`. + +In addition to these two naming conventions, Stealth 1.1+ supports Reply Variants. By adding the name of the service to your reply filename, Stealth will reply to users from that service using the designated reply file. That's a mouthful. Let's try an example. + +For example, if the bot is replying to a message via an action called `hello`: + +Facebook users would receive the reply in `hello.yml+facebook.erb`. +Twilio SMS users would receive the reply in `hello.yml+twilio.erb`. +Every other service would receive the reply in `hello.yml.erb`. + +This allows you to take advantage of things like Facebook Messenger Cards while still maintaining compatibility for users using SMS. + ## Format Stealth reply templates are written in YAML. Stealth doesn't use advanced YAML features, but we do recommend you familiarize yourself with the syntax. In the above reply example, you should be able to see there are 5 replies included in the reply file. **Caveat:** YAML interprets "yes", "no", "true", "false", "y", "n", etc (without quotes) as boolean values. So make sure you wrap them in quotes as we did above. @@ -55,9 +71,34 @@ ## Delays Delays are a common pattern of chatbot design. After a block of text, it's recommended to pause for a bit to give the user a chance to read the message. The duration of the delay depends on the length of the message sent. Stealth will pause for the duration specified. For service integrations that support it (like Facebook), Stealth will send a typing indicator while it is paused. + +### Dynamic Delays + +Rather than specifying an explicit delay duration, you can optionally choose to specify a dynamic duration: + +```yaml +- reply_type: delay + duration: dynamic +``` + +The dynamic delay uses a heuristic to dynamically determine the length of the delay. The previous message sent to the user is examined and depending on it's type and text length (in the case of text replies), an optimal duration is computed. + +If you find that the dynamic delays are too fast for your taste, you can slow them down by setting the multiplier value to something between 0 and 1: + +```ruby +Stealth.config.dynamic_delay_muliplier = 0.5 +``` + +If you find them to be too slow, you can speed them up by setting the multipler to a value greater than 1: + +```ruby +Stealth.config.dynamic_delay_muliplier = 2.5 +``` + +You can set this option by setting the above value in an intializer file, i.e., `config/dynamic_delay_config.rb`. ## Naming Conventions Replies are named after a flow's state (which is also the controller's action). So for a given controller: