npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sarufi

v0.1.4

Published

Sarufi NodeJs SDK to help you interact with Sarufi Conversational API

Downloads

32

Readme

NODEJS SARUFI SDK

TESTS RELEASES DEVELOP PR RELEASE PR

Sarufi NodeJS SDK to help you interact with SARUFI platform inspired by Python Sarufi SDK

Table of Contents

  1. Installation
    1.1 Installation
  2. Use
    2.1. Get your api key
    2.1. Create an empty chatbot
    2.3. Updating your bot
    2.4. Get bot by id
    2.5. Get bots
    2.6. Delete bot
    2.7. Start conversation
    2.8. All responses details

Installation and Use

Installation

From terminal in the root directory of your project, run

npm i sarufi

Use

import sarufi from sarufi

Get your api key

Head to Sarufi, copy your api_key and login:

sarufi.login({ api_key: YOUR_API_KEY })

Create an Empty chatbot

We supply chatbot details

Request payload

{
  "name": "YOUR AWESOME BOT NAME",
  "description": "PUT DESCRIPTION HERE",
  "industry": "YOUR BOT INDUSTRY",
  "intents": {},
  "flows": {},
}

Then we call

// call this first if you haven't logged in.
sarufi.login({ api_key: YOUR_API_KEY }) 

sarufi.createBot({bot: REQUEST PAYLOAD})

NB: For detailed description of intents and flows to be used in conversation, refer to Python Sarufi SDK Docs

Response for successful bot creation

{
  "success": true,
  "bot": {  "name": "YOUR AWESOME BOT NAME",
            "description": "PUT DESCRIPTION HERE",
            "user_id": "YOUR ID",
            "industry": "YOUR BOT INDUSTRY",
            "intents": {}, //intents if they were supplied
            "flows": {}, //flows if they were supplied
            "updated_at": "DATE THE BOT WAS LAST UPDATED",
            "id": "BOT ID",
            "model_name": "BOT MODEL NAME",
            "created_at": "DATE THE BOT WAS CREATED"
  },
  "chat": "({message: string, chat_id?: uknown}) => RETURNS CHAT RESPONSE" //A callable method that starts a chat with your bot, it takes in a string message and optional chat ID
}

Updating your bot

Updating a bot, takes in the same arguments as creating a bot with addition of bot id

Request


// api_key is optional
sarufi.updateBot({bot: REQUEST PAYLOAD, id: YOUR BOT ID, api_key: YOUR_API_KEY})

Response on success, is the same as the response for creating a bot

Get bot by id

We call the following method on sarufi and pass the bot id

Request

// api_key is optional
sarufi.getBot({id: BOT ID, api_key: YOUR_API_KEY})

Response on success, is the same as the response for creating and updating a bot

Get bots

We call the following method on sarufi and pass the bot id

Request

//For version 0.0.1-Beta
sarufi.getBots()

//For versions 0.0.2-Beta and above,
sarufi.getBots({api_key: YOUR_API_KEY}) //This accepts optional paramemters url and api key for persisted authorization tokens.

Response on success

{
    "success": true,
    "bots": [] // Array of all bots you created
}

Delete bot

We call the following method on sarufi and pass the bot id

// api_key is optional
sarufi.deleteBot({id: BOT ID, api_key: YOUR_API_KEY})

Response on success

{
    "success": true,
    "message": "A MESSAGE STATING THAT YOUR BOT HAS BEEN DELETED"
}

Start conversation

There are two methods for this, i.e

  1. bot.chat() this requires us to get a bot we want to have a conversation with and calling a chat method
  2. sarufi.chat() this requires a required message, required bot_id and an optional chat_id as request arguments
// api_key is optional

// bot.chat()
const bot = await sarufi.getBot({id: 'OUR BOT ID', api_key: YOUR_API_KEY})
await bot.chat({message: 'Yooh', channel: 'whatsapp'}) //channel is optional (Default is general)

//sarufi.chat()
await sarufi.chat({message: 'Hey', bot_id: bot.id, chat_id: 'HEYOO', api_key: YOUR_API_KEY, channel: 'whatsapp'})

Response on success

// General Channel
{
  "message":  string| number | unknown | [string] | Record<string, unknown> | [Record<string, unknown>],
  "success": true,
  "memory": { [key: string]: string | unknown},
  [key: string]: string | unknown
}

// Whatsapp Channel
{
  "actions": Array<{
    "send_message"?: string[];
    "send_button"?: any;
    "send_reply_button"?: { 
      "type": string; 
      "body": { "text": string }; 
      "action": any 
    };
    "send_image"?: Array<{ 
      "link": string; 
      "caption": string 
    }>;
    "send_audio"?: any;
    "send_videos"?: any;
  }>;,
 "success": true,
  "memory": { [key: string]: string | unknown},
}

All Responses have

  1. Success property that shows whether or not the request was successful
  2. For failed requests, the response's success property will be false and additional properties for tracing will be added to the response object

Example of failed request

{
  "success": false,
  "message": "MESSAGE", //an error message explaining the error
  "code": "string",
  "status": "NUMBER",
}

Although an error response can have more than those properties, when the status is 500, that will denote an error occured within the sarufi otherwise it will be from an error originating from the remote sarufi server.

All requests have an optional url property that can be passed in case the url changes in the future

NB: For detailed documentation, please visit the Python Sarufi SDK Docs

Developed and Maintained with ❤️ at Flexcode Labs