- Products
- Solutions Use casesBy industry
- Developers
- Resources Connect
- Pricing
You might know what the Nylas CLI is, if not, check out this blog post on Working with the Nylas CLI. And what about Fig and its relation with the Nylas CLI? Here’s another blog post on how to Super Power the Nylas CLI with Fig. Now you may be wondering, what is a Fig Workflow? This blog post is here to discover how you can use Fig Workflows to further Super Power the Nylas CLI.
Setting up our first Fig Workflow
How does the Nylas CLI fit in?
Note that Fig Workflow is currently in Beta, so you may have access to Workflows by the time you’re reading this blog post.
A Fig Workflow is the easiest way to automate your daily developer tasks. By using workflows you can define commands with parameters to avoid typing repetitive commands and help avoid having to recall different commands. Let’s see an example:
By typing:
$ curl http://wttr.in/
We can get the weather in a nice terminal format:
But, who wants to remember that command? A Fig Workflow can help.
Simply, type fig on the terminal window. This will open the Fig dashboard, where we can press Workflows:
Then we can either press New Workflow or even Template Workflow for some nice examples:
When we create a new workflow, we need to name it of course:
On the Script section we need to add the following code:
if [ "{{location}}" == " " ]; then curl http://wttr.in/ else curl http://wttr.in/{{location}} fi
And add an input parameter called location:
It will be saved automatically. So now we can call it from the terminal by typing:
$ fig run
And then choosing our Weather workflow from the list:
Our Location parameter will show up. If we want our default location, we can simply press Spacebar and then Return:
Or we can pass a city name:
And it will be executed:
That’s a great question. In the Nylas CLI we have a lot of commands that we can use to read emails, fetch contacts and create events. Sometimes we need to pass extra parameters and most of the time it’s difficult to remember them all.
Of course, the Nylas CLI is integrated with Fig, so we get autocompletion, which makes our lives easier, but, with Fig Workflow we can make our lives even easier.
Let’s create a workflow to read the contacts in our address book, so just the manually created contacts and not the auto-generated contacts. We can call the workflow Read Contacts:
The Script will be:
nylas api contacts get --source address_book --limit 1
Where the limit will be our input parameter.
Now, we will have two workflows:
And passing the limit:
This will return the requested number of contacts:
Now, at Nylas, we’re always aware of what developers need and want, and developers are using the Nylas CLI to work with webhooks.
So let’s create a workflow to help us when working with webhooks.
First, we know that we can create a script to help us make the output more readable (for context, read Testing Webhooks using the Nylas CLI and Ruby).
But depending on what we use, the default port might be different, for example: 8000 for PHP, 4567 for Ruby and 5000 for Python.
We’re going to create a new workflow called Webhooks and use the following script:
case {{port}} in php) nylas webhook tunnel -f http://127.0.0.1:8000/ ;; ruby) nylas webhook tunnel -f http://127.0.0.1:4567/ ;; python) nylas webhook tunnel -f http://127.0.0.1:5000/ ;; none) nylas webhook tunnel --print ;; esac
Where port will be our input parameter:
When we run it, we can pass php, ruby, python or none.
Here we are using php:
And here we’re using none:
Cool, huh? Wanna share your own Workflows? Tag us on Twitter using our handle @nylas ????
For more information about the Nylas CLI, visit our documentation Nylas CLI.
Don’t miss the action, watch our LiveStream Coding with Nylas:
Blag aka Alvaro Tejada Galindo is a Senior Developer Advocate at Nylas. He loves learning about programming and sharing knowledge with the community. When he’s not coding, he’s spending time with his wife, daughter and son. He loves Punk Music and reading all sorts of books.