1.0.2 • Published 5 months ago

rtlayer-node v1.0.2

Weekly downloads
-
License
ISC
Repository
-
Last release
5 months ago

Overview

rtlayer-node is a Node.js library that provides an easy-to-use interface for interacting with the RTLayer API. RTLayer is a real-time messaging platform that enables you to integrate real-time functionality into your applications.

This documentation will guide you through the installation process, initialization of the RTLayer client, and demonstrate how to send messages using the library.

Installation

To install the rtlayer-node package, use npm:

npm install rtlayer-node

Usage

Importing the RTLayer module

const RTLayer = require('rtlayer-node').default;

Initializing RTLayer

To use the RTLayer API, you need to initialize an instance of the RTLayer class with your API key. You can obtain an API key by signing up for an RTLayer account.

const rtlayer = new RTLayer("your-api-key");

Sending Messages

Use the message method to send real-time messages. The method takes two parameters:

  • message (string or object): The content of the message, which can be either a string or a JSON object.
  • options (object): An optional parameter with the following properties:
    • ttl (number): Time to live for the message in seconds (optional).
    • channel (string): The channel on which to send the message (optional).
// Sending a string message
rtlayer.message("Welcome to MARS!",{
	ttl: 60, // Optional: Time to live for the message in seconds
  channel: "user-id" // // Optional: Channel on which to send the message
});

// Sending a JSON message
rtlayer.message({ headline: "AI Revolution: How Artificial Intelligence is Transforming the Job Market" }, {
    channel: "news"
});

Note: Make sure to replace "your-api-key" with your actual RTLayer API key.

Example

Here is a complete example of using rtlayer-node to send a real-time message:

const RTLayer = require('rtlayer-node').default;

// Replace "your-api-key" with your actual RTLayer API key
const rtlayer = new RTLayer("your-api-key");

// Sending a string message with a personal touch
const personalMessage = "Hello Developers! Just wanted to remind you to take a break and stay hydrated. Happy coding! 😊";

rtlayer.message(personalMessage, {
    ttl: 1,         // Optional: Time to live for the message in seconds
    channel: "devs" // Optional: Channel on which to send the message
});

// Sending a JSON message for a more structured update
const jsonMessage = {
    update: "New version of your favorite programming language released!",
    version: "v3.0.0",
    details: "This release includes exciting new features and performance improvements. Check the documentation for more information."
};

rtlayer.message(jsonMessage, {
    ttl: 1,
    channel: "devs"
});

Conclusion

Experience real-time communication effortlessly with RTLayer. In just 30 minutes, transform your application into a dynamic, engaging experience without the hassle of managing infrastructure.

1.0.2

5 months ago

1.0.1

5 months ago

1.0.0

5 months ago