Skip to content

turnhub/turnio-integration

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

56 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Turn.IO Integrations

A javascript helper library to make it easier to write integrations for Turn.io.

These can be run as google cloud functions.

Here's a sample integration

const app = new TurnIntegration(process.env.SECRET_KEY)
  .context("Language", "table", (message) => ({
    Language: "English",
    Confidence: "Very high",
  }))
  .context("A list of things", "ordered-list", (message) => [
    "first item",
    "second item",
    "third item",
  ])
  .suggest((message) => [
    {
      type: "TEXT",
      title: "Password reset",
      body: "To reset your password click the link on the login page.",
      confidence: 0.4,
    },
  ])
  .action((message) => [
    {
      description: "Change Language",
      payload: {
        really: "yes",
      },
      options: {
        afr_ZA: "Afrikaans",
        eng_ZA: "English",
        zul_ZA: "Zulu",
      },
      callback: ({ message, option, payload: { really } }) => {
        console.log({ message, option, really });
      },
    },
  ])
  .webhook("my-webhook", (req, resp, next) => {
    // expose /webhook/my-webhook as a webhook handler
    // for custom webhooks behaviour
    resp.send({ ok: "cool" });
  })
  .serve();

module.exports = app;

If you want to run this as an expressjs app then:

const server = require("./server");

const port = process.env.PORT || 3000;

server.listen(port, () =>
  console.log(`Example app listening on port ${port}!`)
);

Run it with:

PORT=3000 DEBUG=turn SECRET="<your integrations secret>" yarn start

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published