migme-seagull

Migme Chat

Usage no npm install needed!

<script type="module">
  import migmeSeagull from 'https://cdn.skypack.dev/migme-seagull';
</script>

README

Seagull

Migme chat for javascript

NPM Version Dependency Status devDependency Status Build Status Code Quality Code Coverage

Usage

Installation

Install Node.js

Run npm install

Testing

Run npm test

Using

import Ferry from 'migme-ferry'
import Chat, {Individual, ChatRoom, GroupChat, ChatEvent} from 'migme-seagull'

// Initialise ferry first and wait for connected

// Chat container
const chat = new Chat(ferry)

// Individual chat
const individual = new Individual('exampleaccount', ferry)

// ChatRoom
const chatroom = new ChatRoom(ferry)
chatroom.join('A Chat ChatRoom')

// GroupChat
const groupchat = new GroupChat(ferry)
groupchat.join('XXXXXXXXXXXXXXXXX')

Chat

Get chats

chat.list()
  .then(res => {
    // Got a list of chats
  })
  .catch(err => {
    // there was a problem
  })

Get contacts

chat.contacts()
  .then(res => {
    // Got an array of packets of contact groups and contacts
  })
  .catch(err => {
    // there was a problem
  })

The following methods work with Individual, ChatRoom and GroupChat

Send a message

individual.send('Hello World')

Send a sticker

individual.sendSticker('HSthumbsup')

Send a gift

individual.sendGift('Hi')

Send a gift with a message

individual.sendGift('Hi', 'Here is a gift for you')

Send an image

individual.sendMedia('http://example.com/image.jpg')

Send an image with a message or meta data

individual.sendMedia('http://example.com/image.gif', {
  message: 'I found this image for you',
  mime_type: 'image/gif'
})

Both message and mime_type are optional

Get Emoticon

individual.getEmoticon(['(m_GBbleed)'])

ChatRoom

Create a new chatroom

To create a new chatroom the user needs to be mig level 10 or higher. The chat room name must not contain more than 15 characters

const chatroom = new ChatRoom(ferry)
chatroom
  .create('My Fancy ChatRoom')
  .then(res => {
    // ChatRoom created
  })
  .catch(err => {
    // There was an error
  })

Create chatroom with additional options

All options are optional

const chatroom = new ChatRoom(ferry)
chatroom
  .create('My Fancy ChatRoom', {
    description: '', // string description of chatroom
    keywords: '', // Separated by commas
    language: '', // Three (3) character language code (ISO 639-2)
    allow_kicking: false
  })

Join a chatroom

const chatroom = new ChatRoom(ferry)
chatroom
  .join('My Fancy ChatRoom')
  .then(res => {
    // Joined the room
  })
  .catch(err => {
    // there was a problem
  })

Favorite a chatroom

chatroom.favorite()
  .then(res => {
    // Favorited the room
  })
  .catch(err => {
    // there was a problem
  })

Unfavorite a chatroom

chatroom.unfavorite()
  .then(res => {
    // Favorited the room
  })
  .catch(err => {
    // there was a problem
  })

Get participants

chatroom.participants()
  .then(res => {
    // got the participants
  })
  .catch(err => {
    // there was a problem
  })

Kick a user

chatroom.kick('username')
  .then(res => {
    // User kicked
  })
  .catch(err => {
    // there was a problem
  })

Mute a user

chatroom.mute('username')
  .then(res => {
    // User muted
  })
  .catch(err => {
    // there was a problem
  })

Unmute a user

chatroom.unmute('username')
  .then(res => {
    // User unmuted
  })
  .catch(err => {
    // there was a problem
  })

Leave the chatroom

chatroom.leave()
  .then(res => {
    // Left the chatroom
  })
  .catch(err => {
    // there was a problem
  })

Send a gift

This works the same as in regular chat, however you can pass an extra parameter to specify the destination. By default the destination will be all, which will send to all members of the chatroom.

chatroom.sendGift('Hi', 'Here is a gift for you', 'all')

Chat GroupChat

Create a chat group

const groupchat = new GroupChat(ferry)
groupchat
  .create(['exampleuser', 'anotheruser'])
  .then(res => {
    // GroupChat created
  })
  .catch(err => {
    // There was an error
  })

Join a chat group

const groupchat = new GroupChat(ferry)
groupchat
  .join('XXXXXXXXXXXXXXXXX')
  .then(res => {
    // Joined the group
  })
  .catch(err => {
    // there was a problem
  })

Get participants

groupchat.participants()
  .then(res => {
    // got the participants
  })
  .catch(err => {
    // there was a problem
  })

Invite a user to the group chat

groupchat.invite('exampleuser')
// or
groupchat.invite(['exampleuser', 'anotheruser'])
  .then(res => {
    // got the user status
  })
  .catch(err => {
    // there was a problem
  })

Send a gift

This works the same as in regular chat, however you can pass an extra parameter to specify the destination. By default the destination will be all, which will send to all members of the group chat.

groupchat.sendGift('Hi', 'Here is a gift for you', 'all')

Leave the chat group

groupchat.leave()
  .then(res => {
    // Left the chat group
  })
  .catch(err => {
    // there was a problem
  })

Chat List

const chatlist = new ChatList(ferry)

Get chat list

chatlist.list()
  .then(res => {
    // Got the chat list
  })
  .catch(err => {
    // there was a problem
  })

Chat Room List

const roomlist = new ChatRoomList(ferry)

Get chat room list

roomlist.list()
  .then(res => {
    // Got the chat room list
  })
  .catch(err => {
    // there was a problem
  })

Get chatroom categories

roomlist.categories()
  .then(res => {
    // Got the chat room categories
  })
  .catch(err => {
    // there was a problem
  })

Contacts

const contacts = new Contacts(ferry)

Get Contact list

contacts.list()
  .then(res => {
    // Got the list of contacts
  })
  .catch(err => {
    // there was a problem
  })

Add contact group

contacts.addGroup('Group Name')
  .then(res => {
    // Contact group added
  })
  .catch(err => {
    // there was a problem
  })

Update contact group

contacts.updateGroup(group_id, 'New Group Name')
  .then(res => {
    // Contact group updated
  })
  .catch(err => {
    // there was a problem
  })

Remove contact group

contacts.removeGroup(group_id)
  .then(res => {
    // Contact group removed
  })
  .catch(err => {
    // there was a problem
  })

Move contact to a different group

contacts.move(contact_id, group_id)
  .then(res => {
    // Contact moved
  })
  .catch(err => {
    // there was a problem
  })