Quick Start

This is a function reference for gopherhq-js. View the readme.md file in the the repo that corresponds with this version. Also, view Gopher REST API and the Gopher API Docs for more information.

Quick Start

This is a function reference for gopherhq-js. View the readme.md file in the the repo that corresponds with this version. Also, view Gopher REST API and the Gopher API Docs for more information.

extensionGetSelf

Get information about the extension that corresponds with user's Bearer token (ie, most likely your extension).

extensionGetSelf(cb: function?): Promise
Parameters
cb (function?) Optional callback
Returns
Promise:
Example
const res = await gopherClient.extensionGetSelf();

sendEvent

Send an Event to the extension. This does not require and auth token because the endpoint is meant for 3rd party services. Ex: issue created in Github, or an email response or support ticket received. The Gopher Extension can listen for events, act on tasks or create or delete tasks based on events.

sendEvent(params: object, cb: any): Promise
Parameters
params (object) params
cb (any)
Returns
Promise:
Example
const res = await gopherClient.sendEvent({type: 'event.type', payload: {"foo", "bar"}, event_url: "[unique_event_url]"});

saveExtensionData

Save Gopher extension data which is sent with every webhook related to that extension. This is how an extension persist's user settings specific to that extension. For params and details, see extension saving data API docs

saveExtensionData(data: object, cb: any): Promise
Parameters
data (object) Nestable key value value pairs
cb (any)
Returns
Promise:
Example
const res = await gopherClient.saveExtensionData({ foo: "bar" });

getExtensionData

Get saved Gopher extension data For params and details, see extension get data API docs

getExtensionData(cb: any)
Parameters
cb (any)
Example
const res = await gopherClient.getExtensionData();

makeRequest

Low-level function to make authenticated request to Gopher API

makeRequest(requestOptions: object, cb: function?): Promise
Parameters
requestOptions (object) Axiox-compatible request ooptions
cb (function?) Optional callback.
Returns
Promise:

getLogs

Retrieve logged-in user's extension logs For params and details, see extension saving data API docs

getLogs(filter: object, cb: any): Promise
Parameters
filter (object) Filter. Ex: {type: ['api', 'submit_failed'], extension: ['subdomain'], since: 1517948366, num: 10} )
cb (any)
Returns
Promise: Promise resolving to log results in the form of: {status: "success", logs[...]}

getTasks

Get a filtered list of Gopher tasks

getTasks(params: object, cb: function?): Promise
Parameters
params (object) Arguments for API call
Name Description
params.suppress_webhook boolean Prevent Gopher from firing the task.viewed webhook
params.status boolean Retrieve completed or open tasks
cb (function?) Optional callback function
Returns
Promise:
Example
// Get all open tasks, sorted by due date
const res = await gopherClient.getTasks();
console.log(res.tasks);
// With a callback
gopherClient.getTasks({ limit: 1 }, (err, res) => {
    if (err) done(err);
    console.log(res.tasks);
  });

getTask

Get a Gopher task Passing ?verbose=1 fires a webhook to the extnesion and fetches a rendered HTML email preview of the task

getTask(params: object, cb: any): Promise
Parameters
params (object) request params
Name Description
params.id number taskid
params.verbose boolean Fires webhook to extension, returns rendered HTML emails in a "messages" array if the extension makes these available in the task.viewed webhook resopnse.
cb (any)
Returns
Promise:
Example
const res = await getTask({id: 123});

createTask

Create a new Gopher Task.

createTask(params: any, cb: any, object: any): Promise
Parameters
params (any)
cb (any)
object (any)
Returns
Promise:
Example
const res = await gopherClient.createTask(
    {
      webhook: false,
      suppress_email: true,
      verbose: 1,
      task: {
        command: process.env.EXAMPLE_COMMAND
      },
      send_messages: [
        {
          type: "email",
          subject: "A test email message",
          to: "test@example.com",
          body: [
            {
              type: "html",
              text: "<h1>This is a test</h1>"
            }
          ]
        }
      ]
    });

sendEmail

Send Email and automatically create a Task This creates a gopher task and sends an email. It's a wrapper for createTask with opinionated settings for just sending email.

sendEmail(email: object, cb: any): Promise
Parameters
email (object) Email object. command and one recipient is required.
cb (any)
Returns
Promise:
Example
const res = await gopherClient.sendEmail({
    command: command@my-ext.gopher.email,
    to: "test@exampletask.com",
    cc: [],
    bcc: [],
    from: "test@example.com",
    subject: "Test1",
    body: [
      {
        type: "html",
        text: "<h1>This is a test</h1>"
      }
    ]
  });

updateTask

Update A Gopher Task Used to save data against the task, update content, followup time and more

updateTask(params: any, cb: any, object: any): Promise
Parameters
params (any)
cb (any)
object (any)
Returns
Promise:
Example
const res = await gopherClient.updateTask({
   task: {
    id: 1234,
    reference_email: {
      to: "newRecipient@exampletask.com"
    }
  }});

completeTask

Archive A Gopher Task

completeTask(params: number, cb: any): Promise
Parameters
params (number) Arguments
Name Description
params.task number Task object
params.task.id number Taskid to complete
cb (any)
Returns
Promise:

deleteTask

Permanently Delete A Gopher Task

deleteTask(params: object, cb: any): Promise
Parameters
params (object) Taskid to delete
Name Description
params.task object Task object
params.task.id number Taskid to delete
cb (any)
Returns
Promise:

triggerTask

Trigger a Gopher Task

triggerTask(params: object, cb: any): Promise
Parameters
params (object)
Name Description
params.trigger_url boolean Trigger URL of the task to trigger (get from task object)
params.verbose boolean? Fire webhook and render HTML email response
cb (any)
Returns
Promise:

naturalTime

Resolve Natural Time Format (ex: {naturaltime}@ext.gopher.email)

naturalTime(params: object, cb: any): Promise
Parameters
params (object) params object
Name Description
params.format string Time format to check (ex: 3days)
params.timezone string IANA timezone designation ( https://www.wikiwand.com/en/List_of_tz_database_time_zones ) ex: "America/Los_Angeles"
cb (any)
Returns
Promise:

sendAction

Dispatch an email-based action for a task. (Equivalent to sending an action email.)

sendAction(params: object, cb: any): Promise
Parameters
params (object)
Name Description
params.action string The action string
params.reference_email object The email that would be sent as the action email
params.verbose boolean? Include rendered HTML email contents in API response
cb (any)
Returns
Promise:

getLoggedInUser

Get information about the currently logged in user

getLoggedInUser(cb: function?)
Parameters
cb (function?) Optional callback

invite

Invite users to this extension. If an Auth token is included, the invitation email includes the name of the logged in user who is sending the invitation. "emails" param can be either an array of email addresses, or a string with a single email address.

invite(emails: (array | string), cb: function?)
Parameters
emails ((array | string)) A single email address, or an array of emails to invite
cb (function?) Optional callback (also can be used with promises)

validateWebhook

Validate webhook signature. Set verifyAge to false when testing / mocking HTTP requests. (Server side only)

validateWebhook(webhookSignature: string, webhookTimestamp: number, rawBody: string, verifyAge: boolean?): boolean
Parameters
webhookSignature (string)
webhookTimestamp (number) Unix Timestamp of webhook. Used to prevent reply attack
rawBody (string) Unprocessed http post body
verifyAge (boolean? = true) Use for automated testing
Returns
boolean: Pass / fail webhook validation