Algoan

Algoan

  • Documentation
  • Quick Start
  • API Reference

›Quick Start

Quick Start

  • Introduction
  • Initialize your chatflow
  • Set up your project
  • Set up your service
  • Implement your resthook

    • Application Service
    • Folder Service
    • Aggregation Service
    • Score Service
    • Signature Service

    Score integration

    • Getting Started
    • With a connector
    • Without a connector
    • Using Algoan Connect

    Analytics API Usage

    • Getting Started

Set up your project

Let's get you set up with the world's leading open bank chatflow engine so that you can onboard users on your very own open banking chatflow.

If you're looking for ways to customize your workflow, you may want to check out the API Reference Guide for more detailed information.

Overview

During the chatflow execution, the user will go through different steps and Algoan will send(link) event to your resthook at each step. Depending on the event(link) you'll need to give some information in order for the chatflow to continue properly.

I already have an API! How do I connect it?

Of course, every business has its own API and doesn't want to change its architecture each time it integrates a new partner. We advise to create an independent service.

Follow these steps or download our sample project and skip to part Test your resthook.

We are language agnostic In this example, we are working with node.js, but you can use your favorite language.

Create a Node.js project

Run the following on the command line to create the needed files and dependencies:

mkdir algoan-resthook                   // Creates a project directory
cd algoan-resthook                      // Navigates to the new directory
touch index.js                          // Creates empty index.js file.
npm init                                // Creates package.json. Accept default for all questions.
npm install express body-parser --save  // Installs the express.js http server framework module,
                                        // and then adds them to the dependencies section of package.json file.

Your algoan-resthook directory should look like this:

index.js
node_modules
package.json

Create an HTTP server

Add the following code to index.js:

// Imports dependencies and set up http server
import express from "express";
import bodyParser from "body-parser";

// creates express http server
const app = express().use(bodyParser.json());

// Sets server port and logs message on success
app.listen(process.env.PORT || 1337, () => console.log("Rest is listening"));

This code creates an HTTP server that listens for requests on the default port, or port 1337 if there is no default. For this guide we are using Express, a popular, lightweight HTTP framework, but you can use any framework you love to build your resthook.

Add your resthook endpoint

Add the following code to index.js:

// Create your endpoint to `/resthook` for example
app.post("/resthook", (req, res) => {
  // Returns a '204 OK' response to all requests
  res.status(204).send();

  console.log(req.body.eventName);
});

This code creates a /resthook endpoint that accepts POST requests, checks if the request is a resthook event, then parses the message. This endpoint is where the Algoan Chatbot will send all resthook events.

Note that the endpoint returns a 204 OK response, which tells the Algoan Chatbot that the event has been received and does not need to be sent again. Normally, you will not send this response until you have finished processing the event.

Add resthook verification

Add the following code to index.js:

import crypto from 'crypto';
import hashEquals from 'hash-equals';
const SECRET = 'YOUR SECRET';

...

app.post('/resthook', (req, res) => {
  // stringify the body of event
  const data = JSON.stringify(req.body);
  // get signature
  const headerSignature = req.headers['X-Hub-Signature'];

  // Signature matching
  const expectedSignature = crypto.createHmac('sha256', SECRET).update(data).digest();
  let signature = '';
  if (
    headerSignature.length === 47
    &&
    headerSignature.slice(0, 7) === 'sha256='
  ) {
    signature = headerSignature.slice(5);
  }
  if (hashEquals(signature, expectedSignature)) {
    res.status(204).send();
  } else {
    res.status(403).send();
  }

  ...
}

Test your resthook

Now that you have all the code in place for a basic resthook, it is time to test it by sending requests to your resthook running on localhost.

  1. Run the following on the command line to start your resthook on localhost:

    node index.js
    
  2. From a separate command line prompt, test your resthook verification by substituting your verify token into this cURL request:

    curl \
     -H "Content-Type: application/json" \
     -H "X-Hub-Signature: 1ff6999da68ba08fc226038b9c5f863179da281c" \
     -X POST "localhost:1337/resthook" \
     -d '{"eventName": "MY_CUSTOM_EVENT"}'
    

    If your resthook is working as expected, you should see the following:

    • MY_CUSTOM_EVENT logged to the command line where your node process is running.
    • nothing should be logged in the command line where you sent the cURL request.
← Initialize your chatflowSet up your service →
  • Overview
  • I already have an API! How do I connect it?
  • Create a Node.js project
  • Create an HTTP server
  • Add your resthook endpoint
  • Add resthook verification
  • Test your resthook
Products
About
Developers
Contact
Privacy policy
©Algoan 2021