migme-ferry
v3.2.7
Published
Ferry transports packets to and from fusion/fission
Downloads
13
Readme
Ferry
Ferry transports packets to and from fusion/fission
Usage
Installation
Install Node.js
Run npm install
Testing
Run npm test
Loading Ferry
import Ferry, {Packet, PacketType, FerryEvent} from 'migme-ferry'
// Initialize Ferry by passing in an access_token
const ferry = Ferry({access_token: 'JdFsdKSDf9sbhjasbdk187y19bhsdjahb123iuh'})
// Connect and wait for promise to resolve
ferry.connect().then(() => {
// Ready to send your packets
})
Sending a packet
// Create a new packet
const packet = new Packet(PacketType.MESSAGE)
// Set the fields to be sent
packet.setFields({
destination: 'someone',
content: 'The answer is 42',
chat_type: 1,
message_type: 1,
content_type: 1
})
// Send the packet
ferry.send(packet)
Shorter way:
// Create a new packet with fields
const packet = new Packet(PacketType.MESSAGE, {
destination: 'someone',
content: 'The answer is 42',
chat_type: 1,
message_type: 1,
content_type: 1
})
// Send the packet
ferry.send(packet)
Listen for packet received
ferry.on(FerryEvent.PACKET_RECEIVED, packet => {
// Packet was received
})