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

@cognigy/cognigy-web-client

v3.0.1

Published

The Cognigy web client is a special version of the Cognigy client which contains everything bundled-together so you can get started to connnect and use the Cognigy brain as fast as possible.

Downloads

38

Readme

CognigyWebClient

Repo for the cognigy web client which can be used to connect to the Cognigy.AI platform from a web browser.

This repository supports the two following options:

  • install the cognigy web-client from npm and integrate it within your own build-pipeline e.g. using webpack, rollup and others
  • simply use the "cognigy-web-client.js" and integrate it within your web page. This file does already contain all dependencies, so your ready to go.

Installation

Version for integrating into your own build-pipeline

npm i @cognigy/cognigy-web-client --save

Version for integrating in a web page

  • Download the cognigy-web-client.js within the /static folder
  • Add this javascript file to your webpage and load it: <script src="./cognigy-web-client.js"></script>

Example

This is a minimal example of how to integrate the congigy-web-client into a web-page. Just see the html-example below.

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
        <h1>See your dev-console for the magic that happens.</h1>
        <button id="button">Toggle Record</button>
 
        <script src="./cognigy-web-client.js"></script>
        <script>
            window.onload = function() {
                const options = {
                    /** Required fields */
                    baseUrl: 'server-address',
                    URLToken: 'endoint-url-token',
                    userId: 'your-username',
                    sessionId: 'unique-session-Id',
                    channel: 'my-website',
                    forceWebsockets: false,
                    handleOutput: function(output) {
                        console.log("Text: " + output.text + "   Data: " + output.data);

                        /** use the clients voice synthesis api to 'speak' */
                        client.say(output.text);
                    },

                    /** Optional fields */
                    keepMarkup: true,
                    reconnection: true,
                    interval: 1000,
                    expiresIn: 5000,
                    passthroughIp: "127.0.0.1",
                    handleError: (error) => { console.log(error); },
                    handleException: (error) => { console.log(error); },
                    handlePing: (finalPing) => { console.log("On final ping"); }
                };

                const speechOptions = {
                    /** Required fields */
                    language: 'en-US',
                    
                    /** Optional fields */
                    voiceName: "voice-name",
                    voiceRate: 20,
                    voicePitch: 20,
                }

                const client = new Cognigy.CognigyWebClient(options);
                client.connect()
                    .then(function() {
                        /** Send the event directly */
                        client.sendMessage("I like pizza", undefined);

                        /** Send a transcript that was recorded using the voice recognition api from your browser */
                        client.registerOnRecEnd(function(transcript) {
                            client.sendMessage(transcript, undefined);
                        });
                    })
                    .catch(function(error) {
                        console.log(error);
                    });

                /** a bit js code to make our button work */
                const button = document.getElementById("button");
                if(button !== null) {
                    button.onclick = function() {
                        /** toggles the microphone on/off. The transcript output will be send to the onRecEnd method which you can register using 'client.registerOnRecEnd' */
                        client.toggleRec();
                    }
                }
            }
        </script>
    </body>
</html>