migme-seagull
Version:
Migme Chat
415 lines (352 loc) • 7.45 kB
Markdown
Migme chat for javascript
[](https://www.npmjs.com/package/migme-seagull)
[](https://david-dm.org/migme/seagull)
[](https://david-dm.org/migme/seagull#info=devDependencies)
[](https://codeship.com/projects/76713)
[](https://www.codacy.com)
[](http://codecov.io/github/migme/seagull?branch=master)
Install [Node.js](https://nodejs.org/)
Run `npm install`
Run `npm test`
```js
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')
```
```js
chat.list()
.then(res => {
// Got a list of chats
})
.catch(err => {
// there was a problem
})
```
```js
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```
```js
individual.send('Hello World')
```
```js
individual.sendSticker('HSthumbsup')
```
```js
individual.sendGift('Hi')
```
```js
individual.sendGift('Hi', 'Here is a gift for you')
```
```js
individual.sendMedia('http://example.com/image.jpg')
```
```js
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
```js
individual.getEmoticon(['(m_GBbleed)'])
```
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
```js
const chatroom = new ChatRoom(ferry)
chatroom
.create('My Fancy ChatRoom')
.then(res => {
// ChatRoom created
})
.catch(err => {
// There was an error
})
```
All options are optional
```js
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
})
```
```js
const chatroom = new ChatRoom(ferry)
chatroom
.join('My Fancy ChatRoom')
.then(res => {
// Joined the room
})
.catch(err => {
// there was a problem
})
```
```js
chatroom.favorite()
.then(res => {
// Favorited the room
})
.catch(err => {
// there was a problem
})
```
```js
chatroom.unfavorite()
.then(res => {
// Favorited the room
})
.catch(err => {
// there was a problem
})
```
```js
chatroom.participants()
.then(res => {
// got the participants
})
.catch(err => {
// there was a problem
})
```
```js
chatroom.kick('username')
.then(res => {
// User kicked
})
.catch(err => {
// there was a problem
})
```
```js
chatroom.mute('username')
.then(res => {
// User muted
})
.catch(err => {
// there was a problem
})
```
```js
chatroom.unmute('username')
.then(res => {
// User unmuted
})
.catch(err => {
// there was a problem
})
```
```js
chatroom.leave()
.then(res => {
// Left the chatroom
})
.catch(err => {
// there was a problem
})
```
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.
```js
chatroom.sendGift('Hi', 'Here is a gift for you', 'all')
```
```js
const groupchat = new GroupChat(ferry)
groupchat
.create(['exampleuser', 'anotheruser'])
.then(res => {
// GroupChat created
})
.catch(err => {
// There was an error
})
```
```js
const groupchat = new GroupChat(ferry)
groupchat
.join('XXXXXXXXXXXXXXXXX')
.then(res => {
// Joined the group
})
.catch(err => {
// there was a problem
})
```
```js
groupchat.participants()
.then(res => {
// got the participants
})
.catch(err => {
// there was a problem
})
```
```js
groupchat.invite('exampleuser')
// or
groupchat.invite(['exampleuser', 'anotheruser'])
.then(res => {
// got the user status
})
.catch(err => {
// there was a problem
})
```
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.
```js
groupchat.sendGift('Hi', 'Here is a gift for you', 'all')
```
```js
groupchat.leave()
.then(res => {
// Left the chat group
})
.catch(err => {
// there was a problem
})
```
```js
const chatlist = new ChatList(ferry)
```
```js
chatlist.list()
.then(res => {
// Got the chat list
})
.catch(err => {
// there was a problem
})
```
```js
const roomlist = new ChatRoomList(ferry)
```
```js
roomlist.list()
.then(res => {
// Got the chat room list
})
.catch(err => {
// there was a problem
})
```
```js
roomlist.categories()
.then(res => {
// Got the chat room categories
})
.catch(err => {
// there was a problem
})
```
```js
const contacts = new Contacts(ferry)
```
```js
contacts.list()
.then(res => {
// Got the list of contacts
})
.catch(err => {
// there was a problem
})
```
```js
contacts.addGroup('Group Name')
.then(res => {
// Contact group added
})
.catch(err => {
// there was a problem
})
```
```js
contacts.updateGroup(group_id, 'New Group Name')
.then(res => {
// Contact group updated
})
.catch(err => {
// there was a problem
})
```
```js
contacts.removeGroup(group_id)
.then(res => {
// Contact group removed
})
.catch(err => {
// there was a problem
})
```
```js
contacts.move(contact_id, group_id)
.then(res => {
// Contact moved
})
.catch(err => {
// there was a problem
})
```