UNPKG

migme-seagull

Version:
415 lines (352 loc) 7.45 kB
# Seagull Migme chat for javascript [![NPM Version](https://img.shields.io/npm/v/migme-seagull.svg)](https://www.npmjs.com/package/migme-seagull) [![Dependency Status](https://david-dm.org/migme/seagull.svg)](https://david-dm.org/migme/seagull) [![devDependency Status](https://david-dm.org/migme/seagull/dev-status.svg)](https://david-dm.org/migme/seagull#info=devDependencies) [![Build Status](https://img.shields.io/codeship/441d88a0-cf7b-0132-ed3e-623bdb9b8d89.svg)](https://codeship.com/projects/76713) [![Code Quality](https://img.shields.io/codacy/4766faabfa38494ca8e0b7f7cd7fc0c1.svg)](https://www.codacy.com) [![Code Coverage](http://codecov.io/github/migme/seagull/coverage.svg?branch=master&token=1uynRV5i5a)](http://codecov.io/github/migme/seagull?branch=master) # Usage ## Installation Install [Node.js](https://nodejs.org/) Run `npm install` ## Testing Run `npm test` ## Using ```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') ``` ### Chat #### Get chats ```js chat.list() .then(res => { // Got a list of chats }) .catch(err => { // there was a problem }) ``` #### Get contacts ```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``` ### Send a message ```js individual.send('Hello World') ``` ### Send a sticker ```js individual.sendSticker('HSthumbsup') ``` ### Send a gift ```js individual.sendGift('Hi') ``` ### Send a gift with a message ```js individual.sendGift('Hi', 'Here is a gift for you') ``` ### Send an image ```js individual.sendMedia('http://example.com/image.jpg') ``` ### Send an image with a message or meta data ```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 ### Get Emoticon ```js 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 ```js 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 ```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 }) ``` ### Join a chatroom ```js const chatroom = new ChatRoom(ferry) chatroom .join('My Fancy ChatRoom') .then(res => { // Joined the room }) .catch(err => { // there was a problem }) ``` ### Favorite a chatroom ```js chatroom.favorite() .then(res => { // Favorited the room }) .catch(err => { // there was a problem }) ``` ### Unfavorite a chatroom ```js chatroom.unfavorite() .then(res => { // Favorited the room }) .catch(err => { // there was a problem }) ``` ### Get participants ```js chatroom.participants() .then(res => { // got the participants }) .catch(err => { // there was a problem }) ``` ### Kick a user ```js chatroom.kick('username') .then(res => { // User kicked }) .catch(err => { // there was a problem }) ``` ### Mute a user ```js chatroom.mute('username') .then(res => { // User muted }) .catch(err => { // there was a problem }) ``` ### Unmute a user ```js chatroom.unmute('username') .then(res => { // User unmuted }) .catch(err => { // there was a problem }) ``` ### Leave the chatroom ```js 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. ```js chatroom.sendGift('Hi', 'Here is a gift for you', 'all') ``` ## Chat GroupChat ###Create a chat group ```js const groupchat = new GroupChat(ferry) groupchat .create(['exampleuser', 'anotheruser']) .then(res => { // GroupChat created }) .catch(err => { // There was an error }) ``` ### Join a chat group ```js const groupchat = new GroupChat(ferry) groupchat .join('XXXXXXXXXXXXXXXXX') .then(res => { // Joined the group }) .catch(err => { // there was a problem }) ``` ### Get participants ```js groupchat.participants() .then(res => { // got the participants }) .catch(err => { // there was a problem }) ``` ### Invite a user to the group chat ```js 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. ```js groupchat.sendGift('Hi', 'Here is a gift for you', 'all') ``` ### Leave the chat group ```js groupchat.leave() .then(res => { // Left the chat group }) .catch(err => { // there was a problem }) ``` ## Chat List ```js const chatlist = new ChatList(ferry) ``` ### Get chat list ```js chatlist.list() .then(res => { // Got the chat list }) .catch(err => { // there was a problem }) ``` ## Chat Room List ```js const roomlist = new ChatRoomList(ferry) ``` ### Get chat room list ```js roomlist.list() .then(res => { // Got the chat room list }) .catch(err => { // there was a problem }) ``` ### Get chatroom categories ```js roomlist.categories() .then(res => { // Got the chat room categories }) .catch(err => { // there was a problem }) ``` ## Contacts ```js const contacts = new Contacts(ferry) ``` ### Get Contact list ```js contacts.list() .then(res => { // Got the list of contacts }) .catch(err => { // there was a problem }) ``` ### Add contact group ```js contacts.addGroup('Group Name') .then(res => { // Contact group added }) .catch(err => { // there was a problem }) ``` ### Update contact group ```js contacts.updateGroup(group_id, 'New Group Name') .then(res => { // Contact group updated }) .catch(err => { // there was a problem }) ``` ### Remove contact group ```js contacts.removeGroup(group_id) .then(res => { // Contact group removed }) .catch(err => { // there was a problem }) ``` ### Move contact to a different group ```js contacts.move(contact_id, group_id) .then(res => { // Contact moved }) .catch(err => { // there was a problem }) ```