# @turnio/integration

> Tools for building Turn.io integrations with Javascript

Latest version **1.3.11** (published 2020-06-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install @turnio/integration
pnpm add @turnio/integration
yarn add @turnio/integration
bun add @turnio/integration
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.3.11 |
| Published | 2020-06-16 |
| First published | 2019-10-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 20 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Simon de Haan |
| Maintainers | sdehaan |

## Links

- npm: https://www.npmjs.com/package/@turnio/integration
- Repository: https://github.com/turnhub/turnio-integration
- npm.io page: https://npm.io/package/@turnio/integration

## Dependencies (3)

- [debug](https://npm.io/package/debug.md) ^4.1.1
- [express](https://npm.io/package/express.md) ^4.17.1
- [body-parser](https://npm.io/package/body-parser.md) ^1.19.0

## Recent versions

- 1.3.11 (latest) — 2020-06-16
- 1.3.10 — 2020-06-16
- 1.3.9 — 2020-05-02
- 1.3.8 — 2020-05-02
- 1.3.7 — 2020-05-02
- 1.3.6 — 2020-04-29
- 1.3.5 — 2020-04-29
- 1.3.4 — 2020-04-29
- 1.3.3 — 2020-04-29
- 1.3.2 — 2020-04-24
- 1.3.1 — 2020-04-23
- 1.2.4 — 2020-04-06
- 1.2.3 — 2019-12-03
- 1.2.2 — 2019-12-03
- 1.2.1 — 2019-12-03
- … 8 more at https://npm.io/package/@turnio/integration/versions

## README

# 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

```javascript
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:

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

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

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

Run it with:

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

---
_Source: https://npm.io/package/@turnio/integration · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
