Real-Time Sentiment Analysis
@pravin
code:
data:privatelast updated:5 years ago
today
Build integrations remarkably fast!
You're viewing a public workflow template.
Sign up to customize, add steps, modify code and more.
Join 1,000,000+ developers using the Pipedream platform
steps.
trigger
HTTP API
Deploy to generate unique URL
This workflow runs on Pipedream's servers and is triggered by HTTP / Webhook requests.
steps.
triage_event_payload
auth
to use OAuth tokens and API keys in code via theauths object
code
Write any Node.jscodeand use anynpm package. You can alsoexport datafor use in later steps via return or this.key = 'value', pass input data to your code viaparams, and maintain state across executions with$checkpoint.
async (event, steps) => {
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
}
22
const _ = require('lodash')

//end workflow execution if no text is found
if(_.get(event,'body.text',false) === false) {
    const msg = `Could not find text to analyze. To use this workflow, make an HTTP POST request to your endpoint the following payload: {"text":"TEXT_TO_ANALYZE"}`
    
    //return the payload to the client using $respond
    $respond({
        status: 400,
        body: msg 
    })

    //if returning a response to the client is not enabled, console log the URL to enable it
    if(event.url.search('pipedream_response=1') === -1) {
        console.log(`Make requests to https://${event.headers.host}?pipedream_response=1 to return messages to the client` )
    }

    //end the workflow execution
    $end(msg)
}
steps.
analyze_text
auth
to use OAuth tokens and API keys in code via theauths object
code
Write any Node.jscodeand use anynpm package. You can alsoexport datafor use in later steps via return or this.key = 'value', pass input data to your code viaparams, and maintain state across executions with$checkpoint.
async (event, steps) => {
1
2
3
4
}
5
var Sentiment = require('sentiment');
var sentiment = new Sentiment();
this.sentiment = sentiment.analyze(event.body.text)
steps.
process_data
auth
to use OAuth tokens and API keys in code via theauths object
code
Write any Node.jscodeand use anynpm package. You can alsoexport datafor use in later steps via return or this.key = 'value', pass input data to your code viaparams, and maintain state across executions with$checkpoint.
async (event, steps) => {
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
}
19
//create a payload for Pipedream's SQL service
this.payload = {
    "timestamp": steps.trigger.context.ts,
    "text": event.body.text,
    "sentiment": steps.analyze_text.sentiment
}

//return the payload to the client using $respond
$respond({
    status: 200,
    body: this.payload
})

//if returning a response to the client is not enabled, console log the URL to enable it 
if(event.url.search('pipedream_response=1') === -1) {
    console.log(`Inspect the results below or make an HTTP POST request to https://${event.headers.host}?pipedream_response=1 to return the sentiment score to the client` )
}
steps.
sql
Pipedream automatically generates a table and schema based on the event shape.
params
Table Name

Enter the name of the table (e.g., my_table_name) to load the payload data into. Pipedream's SQL service automatically creates the table and adapts the schema to your data.

sentimentTest
string ·params.table
Payload

Enter a reference to the data (for example, event.body or steps.step_name.return_value) you'd like to insert into the table. Pipedream’s SQL service automatically converts the data to JSON and maps the table schema to its keys.

{{steps.process_data.payload}}
string ·params.payload
code
async params => {
1
2
3
4
5
}
6
  $send.sql({
    table: params.table,
    payload: params.payload,
  })