npm package: @mesibo/core
Description: mesibo real-time messaging, voice and video call APIs for Node.js
Author: mesibo
Latest version: 2.6.1

# mesibo Node.js API

Real-time messaging, voice and video call APIs for Node.js — powered by [mesibo](https://mesibo.com).

## Requirements

- Node.js 21 or later (native WebSocket support)
- A mesibo account and access token — sign up at [mesibo.com](https://mesibo.com)

## Installation

```bash
npm install @mesibo/core
```

## Quick Start

```js
const { Mesibo } = require('@mesibo/core');

var listener = {
    Mesibo_onConnectionStatus: function(status, value) {
        if(status === 1 /* ONLINE */) {
            var p = api.getProfile('destination_address', 0);
            var msg = p.newMessage();
            msg.message = 'Hello from Node.js!';
            msg.send();
        }
    },

    Mesibo_onMessage: function(msg) {
        if(msg.isPresence()) return;
        console.log('from:', msg.getSenderProfile().getAddress(),
                    'text:', msg.message);
    },

    Mesibo_onMessageUpdate: function(msg) {},

    Mesibo_onMessageStatus: function(msg) {
        var label = msg.isSent()       ? 'sent'      :
                    msg.isDelivered()  ? 'delivered'  :
                    msg.isReadByPeer() ? 'read'       :
                    msg.isFailed()     ? 'failed'     : msg.getStatus();
        console.log('msg', msg.getMessageId(), 'status:', label);
    },

    Mesibo_onPresence: function(p) {
        var addr = p.getSenderProfile().getAddress();
        if(p.isTyping())       console.log(addr, 'is typing...');
        else if(p.isOnline())  console.log(addr, 'came online');
        else if(p.isOffline()) console.log(addr, 'went offline');
    },

    Mesibo_onProfileUpdated: function(profile) {
        console.log('profile:', profile.getAddress(), profile.getName());
    }
};

var api = Mesibo.getInstance();
api.setCredentials('YOUR_ACCESS_TOKEN', 0);
api.setListener(listener);
api.start();
```

See the `examples/` folder for a complete working example, or follow the [Get Started tutorial](https://docs.mesibo.com/tutorials/get-started/).

## API Overview

### Initialisation

```js
var api = Mesibo.getInstance();
api.setCredentials(token, uid);   // uid = 0 for auto
api.setListener(listener);
api.start();
api.stop();
```

### Sending Messages

```js
var profile = api.getProfile('address', 0);

// Text message
var msg = profile.newMessage();
msg.message = 'Hello!';
msg.send();

// Typing presence (cleared automatically by mesibo)
var presence = profile.newPresence();
presence.sendTyping();
```

### Receiving Messages

Implement these callbacks in your listener:

| Callback | Description |
|---|---|
| `Mesibo_onConnectionStatus(status, value)` | Connection state changes |
| `Mesibo_onMessage(msg)` | Incoming message or presence |
| `Mesibo_onMessageUpdate(msg)` | Message edited or status updated |
| `Mesibo_onMessageStatus(msg)` | Delivery/read status of sent messages |
| `Mesibo_onPresence(p)` | Typing, online/offline indicators |
| `Mesibo_onProfileUpdated(profile)` | Profile name/picture updated |

### Message Methods

```js
msg.getMessageId()       // unique message ID
msg.getSenderProfile()   // MesiboProfile of sender
msg.getStatus()          // raw status code
msg.isSent()
msg.isDelivered()
msg.isReadByPeer()
msg.isUnread()
msg.isFailed()
msg.isIncoming()
msg.isOutgoing()
msg.isPresence()
msg.isGroupMessage()
msg.isModified()
```

### Presence Methods

```js
p.isTyping()
p.isTypingCleared()
p.isOnline()
p.isOffline()
p.hasJoined()
p.hasLeft()
```

## Resources

- [Get Started Tutorial](https://docs.mesibo.com/tutorials/get-started/)
- [Documentation](https://docs.mesibo.com/)
- [GitHub](https://github.com/mesibo)