Options
All
  • Public
  • Public/Protected
  • All
Menu

Class WebhookJob

A job that is triggered when a webhook receives a request.

Hierarchy

  • Job
    • WebhookJob

Index

Constructors

constructor

Properties

Protected _id

_id: string

Protected _lifeCycle

_lifeCycle: LifeEvent[]

Protected _locallyAvailable

_locallyAvailable: boolean

Protected _name

_name: string

Protected _nest

_nest: Nest

Protected _properties

_properties: any

Protected _request

_request: any

Protected _response

_response: any

Protected _responseSent

_responseSent: boolean

Protected _tunnel

_tunnel: Tunnel

Protected _type

_type: string

Protected e

Accessors

files

  • get files(): any

id

  • get id(): string

isLocallyAvailable

  • get isLocallyAvailable(): boolean

lifeCycle

locallyAvailable

  • set locallyAvailable(available: boolean): void

name

  • get name(): string
  • set name(name: string): void

nameProper

  • get nameProper(): string

nest

  • get nest(): Nest
  • set nest(nest: Nest): void

path

  • get path(): string
  • set path(path: string): void

properties

  • get properties(): any

propertyValues

  • set propertyValues(properties: Object): void

request

  • get request(): any

response

  • get response(): any

responseSent

  • get responseSent(): boolean
  • set responseSent(sent: boolean): void
  • Get if the response to the webhook was already sent or not.

    Returns boolean

  • Set if the response to the webhook was already sent or not.

    Parameters

    • sent: boolean

    Returns void

size

  • get size(): any

sizeBytes

  • get sizeBytes(): any

tunnel

type

  • get type(): string

Methods

Protected createLifeEvent

  • createLifeEvent(verb: string, start: string, finish: string): void

email

  • Sends an email.

    Parameters

    • emailOptions: EmailOptions

      Email options

      Sending pug template email example

      // my_tunnel.js
      tunnel.run(function (job, nest) {
           job.email({
               subject: "Test email from pug template",
               to: "john.smith@example.com",
               template: __dirname + "./template_files/my_email.pug"
           });
      });
      
      // template_files/my_email.pug
      h1="Example email!"
      p="Got job ID " + job.getId()
      

      Sending plain-text email

      tunnel.run(function (job, nest) {
           job.email({
               subject: "Test email with hard-coded plain-text",
               to: "john.smith@example.com",
               text: "My email body!"
           });
      });
      

      Sending html email

      tunnel.run(function (job, nest) {
           job.email({
               subject: "Test email with hard-coded html",
               to: "john.smith@example.com",
               html: "<h1>My email body!</h1>"
           });
      });
      

    Returns void

fail

  • fail(reason: string): void
  • Function to call to fail a job while in a tunnel.

    Parameters

    • reason: string

    Returns void

getDataAsString

  • getDataAsString(callback: function): void
  • Get a string from the request body. The given callback is given a string parameter.

    Example

    webhookJob.getDataAsString(function(requestBody){
        console.log(requestBody);
    });
    

    Parameters

    • callback: function
        • (data: string): void
        • Parameters

          • data: string

          Returns void

    Returns void

getFile

  • getFile(index: any): any

getFormDataFiles

  • getFormDataFiles(): Array<any>
  • Returns FileJobs made from _files sent via FormData to the webhook.

    Returns Array<any>

getFormDataValue

  • getFormDataValue(key: string): any

getFormDataValues

  • getFormDataValues(): any

getJSON

  • getJSON(): any

getParameter

  • getParameter(key: string): any
  • Returns a parameter from both the query string and form-data.

    Parameters

    • key: string

    Returns any

getParameters

  • getParameters(): any

getProperty

getPropertyType

  • getPropertyType(key: string): any
  • Get the type of a property.

    Example

    job.setPropertyValue("My Job Number", 123456);
    
    console.log(job.getPropertyType("My Job Number"));
    // "number"
    

    Parameters

    • key: string

    Returns any

getPropertyValue

  • getPropertyValue(key: string): any

getQueryStringValue

  • getQueryStringValue(parameter: string): any
  • Return a specific URL parameter.

    Example

    // Webhook URL: /hooks/my/hook?customer_id=MyCust
    var customer_id = webhookJob.getUrlParameter("customer_id");
    // customer_id => MyCust
    

    Parameters

    • parameter: string

    Returns any

getQueryStringValues

  • getQueryStringValues(): any
  • Return all URl parameters.

    • Example

      // Webhook URL: /hooks/my/hook?customer_id=MyCust&file_name=MyFile.zip
      var query = webhookJob.getUrlParameters();
      // query => {customer_id: "MyCust", file_name: "MyFile.zip"}
      

    Returns any

isFile

  • isFile(): any

isFolder

  • isFolder(): any

log

  • log(level: number, message: string): void
  • Add a message to the log with this job as the actor.

    Parameters

    • level: number

      0 = debug, 1 = info, 2, = warning, 3 = error

    • message: string

      Log message

    Returns void

move

  • move(destinationNest: any, callback: any): void
  • Move function error.

    Parameters

    • destinationNest: any
    • callback: any

    Returns void

pack

  • pack(callback: function): void
  • Packs the job instance and file together in a zip. Returns a PackJob in the parameter of the callback.

    Parameters

    • callback: function

      Example

      job.pack(function(packJob){
           packJob.move(packed_folder_nest);
      });
      

    Returns void

rename

  • rename(name: string): any

setPropertyValue

  • setPropertyValue(key: string, value: any): void
  • Attach job specific data to the job instance.

    Example

    job.setPropertyValue("My Job Number", 123456);
    
    console.log(job.getPropertyValue("My Job Number"));
    // 123456
    

    Parameters

    • key: string
    • value: any

    Returns void

toString

  • toString(): string

transfer

  • transfer(tunnel: Tunnel): void

unpack

  • unpack(callback: function): void
  • Unpacks a packed job. Returns a the original unpacked job in the parameter of the callback.

    Parameters

    • callback: function

      Example

      packedJob.unpack(function(unpackedJob){
          console.log("Unpacked", unpackedJob.name);
          unpackedJob.move(unpacked_folder);
          packedJob.remove();
      });
      
        • (job: Job): void
        • Parameters

          Returns void

    Returns void

Generated using TypeDoc