-
Notifications
You must be signed in to change notification settings - Fork 14
feat: adds ruby example structure #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
matheuspoleza
wants to merge
1
commit into
master
Choose a base branch
from
ruby-example
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
source "https://rubygems.org" | ||
|
||
gem 'faraday' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
faraday (1.7.0) | ||
faraday-em_http (~> 1.0) | ||
faraday-em_synchrony (~> 1.0) | ||
faraday-excon (~> 1.1) | ||
faraday-httpclient (~> 1.0.1) | ||
faraday-net_http (~> 1.0) | ||
faraday-net_http_persistent (~> 1.1) | ||
faraday-patron (~> 1.0) | ||
faraday-rack (~> 1.0) | ||
multipart-post (>= 1.2, < 3) | ||
ruby2_keywords (>= 0.0.4) | ||
faraday-em_http (1.0.0) | ||
faraday-em_synchrony (1.0.0) | ||
faraday-excon (1.1.0) | ||
faraday-httpclient (1.0.1) | ||
faraday-net_http (1.0.1) | ||
faraday-net_http_persistent (1.2.0) | ||
faraday-patron (1.0.0) | ||
faraday-rack (1.0.0) | ||
multipart-post (2.1.1) | ||
ruby2_keywords (0.0.5) | ||
|
||
PLATFORMS | ||
universal-darwin-20 | ||
|
||
DEPENDENCIES | ||
faraday | ||
|
||
BUNDLED WITH | ||
2.2.25 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Voiceflow API Node.js Example | ||
|
||
Set up your Voiceflow project with Ruby in a matter of minutes. This example can be adapted to run as a server. | ||
|
||
This example enables you to chat with your project on the terminal. | ||
|
||
## Documentation | ||
|
||
For additional information about the Voiceflow API, visit the [documentation](https://www.voiceflow.com/api/dialog-manager). | ||
|
||
## Setup | ||
|
||
1. If you do not have ruby, install ruby and [bundler](https://bundler.io/) (ruby gems/dependencies manager) from [ruby-lang.org](https://www.ruby-lang.org/en/documentation/installation/), or follow an equivalent guide. | ||
2. In this folder, run `bundle install`. | ||
3. Replace `'YOUR_API_KEY_HERE'` and `'YOUR_VERSION_ID_HERE'` in `index.rb` with your API Key and Voiceflow project version ID. You can find them under the integrations tab: | ||
|
||
<img src="https://user-images.githubusercontent.com/5643574/129422436-04d964d3-85a0-402d-ae5e-d6e84723da5e.png" width=800 /> | ||
|
||
4. run `bundle exect ruby main.rb` to start your chat! | ||
|
||
## Example | ||
|
||
What it looks like in action: | ||
|
||
``` | ||
➜ nodeJS git:(master) ✗ npm run start | ||
|
||
> [email protected] start | ||
> node index.js | ||
|
||
> What is your name?: tyler | ||
what can I do for you? | ||
... | ||
> Say something: send email | ||
who is the recipient? | ||
... | ||
> Say something: [email protected] | ||
what is the title of your email? | ||
... | ||
> Say something: How was your day? | ||
sending the email for [email protected] called "How was your day?". Is that correct? | ||
... | ||
> Say something: yes | ||
successfully sent the email for [email protected] called "How was your day?" | ||
The end! Start me again with `npm run start` | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
require "faraday" | ||
require "json" | ||
|
||
API_KEY = "YOUR_API_KEY_HERE" # it should look like this: VF.XXXXXXX.XXXXXX... keep this a secret! | ||
VERSION_ID = "YOUR_VERSION_ID_HERE" # your voiceflow project versionID, find it under the "integrations" tab | ||
|
||
def interact(user_id, request) | ||
puts "..." | ||
puts user_id, request.to_json | ||
|
||
# call the voiceflow api with the user's name & request, get back a response | ||
response = Faraday.post( | ||
"https://general-runtime.voiceflow.com/state/#{VERSION_ID}/user/#{user_id}/interact", | ||
{ | ||
headers: {"Content-Type" => "application/json", "Authorization": API_KEY }, | ||
body: request | ||
} | ||
) | ||
|
||
if response.nil? | ||
return false | ||
end | ||
|
||
# loop through the response | ||
response.data.each do |trace| | ||
# if trace.type == "speak" | ||
# puts trace.payload.message | ||
# elsif trace.type == 'text' | ||
# puts trace.payload.text | ||
# elsif trace.type == 'end' | ||
# # an end trace means the the voiceflow dialog has ended | ||
# return false | ||
end | ||
|
||
return true | ||
end | ||
|
||
def main() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you technically don't even need this |
||
puts "> What is your name?" | ||
user_id = gets.chomp.split(',')[0] | ||
|
||
is_running = interact(user_id, { type: 'launch' }) | ||
|
||
while is_running do | ||
puts "> Say something" | ||
next_input = gets.chomp.split(',')[0] | ||
# send a simple text type request with the user input | ||
is_running = interact(user_id, { type: 'text', payload: next_input }); | ||
end | ||
|
||
puts "The end! Start me again with bundle exect ruby main.rb" | ||
end | ||
|
||
main() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might want to change this to be Ruby specific