Scheduled Tweet Manager
@raymondcamden
code:
data:privatelast updated:4 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
Cron Scheduler
Deploy to configure a custom schedule
This workflow runs on Pipedream's servers and is triggered on a custom schedule.
steps.
constants
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
return {
  google_sheet_id: "1y7sW4Qv9xHIA9tOXhgOtIB6yN1LegSMmf0GrlbHsSRk"
}
steps.
get_values
Get values from Google Sheet using the Google APIs Node.js Client and the spreadsheets.values.get method: https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/get
auth
(auths.google_sheets)
params
SpreadhsheetId

The ID of the spreadsheet to insert rows into. The spreadsheetID can be found in the URL when viewing your Google sheet. E.g., https://docs.google.com/spreadsheets/d/[spreadsheetId]/edit#gid=0

 
string ·params.spreadhsheetId
Range

The A1 notation of the values to retrieve. E.g., A1:E5 or Sheet1!A1:E5

 
A1:E5
string ·params.range
code
async (params, auths) => {
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
}
16
const {google} = require('googleapis')

const auth = new google.auth.OAuth2()
auth.setCredentials({ access_token: auths.google_sheets.oauth_access_token })
const sheets = await google.sheets({version: 'v4', auth});

const response = await sheets.spreadsheets.values.get({
  spreadsheetId: params.spreadhsheetId,
  range: params.range
})

this.status = response.status
this.statusText = response.statusText
return response.data
steps.
get_earliest
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
23
24
25
26
27
28
}
29
// loop over all cells, if any, and filter to those before now
let earliest = new Date(3000,1,1);
let now = new Date();

let selected = -1;
let cells = steps.get_values.$return_value.values;
if(!cells) $end('No content from sheet.');

cells.forEach((v,i) => {
  let thisDate = new Date(v[1]);
  
  if(thisDate < now && thisDate < earliest) {
    earliest = thisDate;
    selected = i;
    console.log('set selected to '+i)
  }
});

if(selected >= 0) {
  // why the plus one? we start reading at the second row
  return {
    index: selected+1, 
    indexPlusOne: selected+2,
    text: cells[selected][0]
  };
} else $end('No values to select.');
steps.
post_tweet
Post a tweet.
auth
(auths.twitter)
params
Status
 
string ·params.status
Optional
code
async (params, auths) => {
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
}
23
const axios = require('axios')
const {status, in_reply_to_status_id, auto_populate_reply_metadata, exclude_reply_user_ids, attachment_url, media_ids, possibly_sensitive, lat, long, place_id, display_coordinates, trim_user, enable_dmcommands, fail_dmcommands, card_uri} = params
const body = {
  config: {
    url: `https://api.twitter.com/1.1/statuses/update.json`,
    method: 'POST',
    params,
  },
  token: {
    key: auths.twitter.oauth_access_token,
    secret: auths.twitter.oauth_refresh_token,
  },
}
const proxy = "https://api.pipedream.com/v1/oauth1/app_13GhY1"
const resp = await axios.post(proxy,body)

const {messages, data} = resp.data
for (const message of messages) {
  console.log(message)
}
return data
steps.
delete_rows_or_columns_from_sheet
Deletes rows or columns from a specific sheet in a Google Spreadsheet
auth
(auths.google_sheets)
params
Sheet ID

The ID of the sheet you'd like to add a row to, retrieved using the Get Spreadsheet Action

 
Sheet1
integer ·params.sheetId
Dimension

Are you deleting ROWS or COLUMNS?

string ·params.dimension
Start Index

The 0-based index of the row or column you'd like to start deleting from, inclusive. For example, row 1 has an index of 0, row 2 has an index of 1. Column A has an index of 0, column B has an index of 1.

 
0
number ·params.startIndex
End Index

The 0-based index of the row or column where you'd like to stop your deletion. Unlike the Start Index, this parameter is exclusive. For example, to delete Row 1 of your spreadsheet, pass a Start Index of 0 and an End Index of 1.

 
1
number ·params.endIndex
Spreadsheet ID

The ID of your spreadsheet. For example, the 1bn9xlC8asUl3OR12LOuJ7Z_4F6nzIOYdTDm1Ec1HCHw in the URL https://docs.google.com/spreadsheets/d/1bn9xlC8asUl3OR12LOuJ7Z_4F6nzIOYdTDm1Ec1HCHw/edit

 
string ·params.spreadsheetId
Optional
code
async (params, auths) => {
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
}
28
const data = {
  requests: [
    {
      "deleteDimension": {
        "range": {
          "sheetId": params.sheetId,
          "dimension": params.dimension,
          "startIndex": params.startIndex,
          "endIndex": params.endIndex,
        }
      }
    }
  ],
  includeSpreadsheetInResponse: params.includeSpreadsheetInResponse,
}

const config = {
  method: "post",
  url: `https://sheets.googleapis.com/v4/spreadsheets/${params.spreadsheetId}:batchUpdate`,
  headers: {
    Authorization: `Bearer ${auths.google_sheets.oauth_access_token}`,
  },
  data,
}
return await require("@pipedreamhq/platform").axios(this, config)