> For the complete documentation index, see [llms.txt](https://help.pickyassist.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.pickyassist.com/~/changes/UIUApFI15X6M1wQJrFRy/api-documentation-v2/sample-codes/node-js.md).

# Node JS

## Sample Code in Node JS with Express Server

Here it goes the example of how to implement a very simple “parrot” bot (that replies exactly what has been said to it) using Node.js with an Express server:

The below sample code is shared by one of the picky assist customer based in Chile.

```javascript
const bodyParser = require('body-parser');
const express = require('express');
const app = express();

// enable extended to let nested POST
app.use(bodyParser.urlencoded({extended: true}));

// webhook set up
// on production authenticate each POST - you could add a token to the URL
app.post('/webhook/', (req, res) => {
  // for development only - console log the post content
  console.log(req.body);

  // builds the answer replicating the message sent
  let reply = {
    'message-out': req.body['message-in'],
    'delay': 0,
  };

  // Sends the reply - ENSURE a JSON response add JSON.stringfy just to be safe
  res.status(200).send(JSON.stringify(reply));
});

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

### Node Js - Push API -Http method

```javascript
var http = require("https");

var options = {
  "method": "POST",
  "hostname": "pickyassist.com",
  "port": null,
  "path": "/app/api/v2/push",
  "headers": {
    "content-type": "application/json",
  }
};

var req = http.request(options, function (res) {
  var chunks = [];

  res.on("data", function (chunk) {
    chunks.push(chunk);
  });

  res.on("end", function () {
    var body = Buffer.concat(chunks);
    console.log(body.toString());
  });
});

req.write(JSON.stringify({
  token: 'c2a0b6221c5dd55ceb09ae1f74e46521756d',
  'priority ': 0,
  application: '2',
  sleep: 0,
  globalmessage: '',
  globalmedia: '',
  data: [{number: '1212', message: 'Test'}]
}));
req.end();
```

### Node Js - Unirest

```javascript
var unirest = require("unirest");

var req = unirest("POST", "https://pickyassist.com/app/api/v2/push");


req.headers({
  "content-type": "application/json"
});

req.type("json");
req.send({
  "token": "c2a0b6221c5dd55ceb09ae1f74e46521756d",
  "priority ": 0,
  "application": "2",
  "sleep": 0,
  "globalmessage": "",
  "globalmedia": "",
  "data": [
    {
      "number": "1212",
      "message": "Test"
    }
  ]
});

req.end(function (res) {
  if (res.error) throw new Error(res.error);

  console.log(res.body);
});

```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://help.pickyassist.com/~/changes/UIUApFI15X6M1wQJrFRy/api-documentation-v2/sample-codes/node-js.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
