Skip to content

Latest commit

 

History

History
448 lines (330 loc) · 9.83 KB

README.md

File metadata and controls

448 lines (330 loc) · 9.83 KB

Kik Node API

A chatting API for kik built with Node.js, based on https://github.com/tomer8007/kik-bot-api-unofficial

THIS IS NOT AN OFFICIAL API

npm npm

Join the group chat on kik #kiknodeapi


Feeling generous? Send me a BTC donation at bc1q7fg5r35e4hqaqxgqaleyza9j3k0dm7efknp9lj

Installation

NPM:

npm i kik-node-api

Usage

Events
  1. The Basics
  2. Group Events
  3. Private Events
Requests
  1. Common Requests
  2. Group Requests
  3. Profile Requests

Getting Started

You can use the API by creating an instance of KikClient, you'll use it to listen to events and send requests to kik

const KikClient = require("kik-node-api");

Kik = new KikClient({
   promptCaptchas: true,
   device: {
       
   },
   logger: {
      file: ["warning", "error", "info", "raw"],
      console: ["warning", "error", "info", "raw"]
   }
});

Kik.authenticate(username, password)

promptCaptchas: prompt in the console to solve captchas. If not you must handle it yourself using the event

logger: configuration for the logger, the array contains the type of logs

The user object:

user: { 
    jid: "[email protected]", 
    username: "kikteam",
    displayName: "Kik Team",
    pic: "http://profilepics.cf.kik.com/luN9IXX3a4sks-RzyiC7xlK-HdE"
}

The group object

group: {
    jid: "[email protected]",
    code: "#kikbotapi",
    name: "Kik Bot API Unofficial",
    users: [
        {jid: "jid1", isOwner: true, isAdmin: true},
        {jid: "jid2", isAdmin: true},
        {jid: "jid3"}
    ]
}

private groups have a code of null

Events

The Basics

KikClient uses Node's Event Emitter class to handle events, all events are attached in the following way:

Kik.on(eventname, (param1, param2) => {
    //do stuff with params here
})

Below are the details of all events emitted by the KikClient class

Connected
Kik.on("connected", () => {
    console.log("Connected")
})
Authenticated
Kik.on("authenticated", (isAnonymous) => {
    console.log("Authenticated")
})

isAnonymous: if true the authentication was done anonymously (no username/password)

Received Roster
Kik.on("receivedroster", (groups, friends) => {
    console.log(groups);
    console.log(friends)
})

groups: an array of group objects representing the groups you are in

friends: an array of user objects, each representing a friend

Received Captcha
Kik.on("receivedcaptcha", (captchaUrl) => {
    console.log("Please solve captcha" + captchaUrl)
})

captchaUrl: url to the captcha page

Received JID Info
Kik.on("receivedjidinfo", (users) => {
    console.log("We got peer info:");
    console.log(users)
})

users: an array of user objects returned as a result of requesting jids

Group Events

Received Group Message
Kik.on("receivedgroupmsg", (groupJid, senderJid, msg) => {
    console.log(`Received message from ${senderJid} in group ${groupJid}`)
})
Received Group Image
Kik.on("receivedgroupimg", (groupJid, senderJid, img) => {
    console.log(`Received image from ${sender.jid} in group ${group.jid}`)
})

img: a buffer object representing the image

Group is Typing
Kik.on("grouptyping", (groupJid, senderJid, isTyping) => {
    if(isTyping){
        console.log(`${senderJid} is typing in ${groupJid}`)
    }else{
        console.log(`${senderJid} stopped typing in ${groupJid}`)
    }
})

isTyping: true if the user is typing, false if they stopped

User Left Group
Kik.on("userleftgroup", (groupJid, userJid, wasKicked) => {
    console.log(`${userJid} left the group: ${groupJid}`)
})

wasKicked: true if the user was kicked

User Joined Group
Kik.on("userjoinedgroup", (groupJid, userJid, wasInvited) => {
    console.log(`${userJid} joined the group: ${groupJid}`)
})

wasInvited: true if the user was invited

Private Events

Received Private Message
Kik.on("receivedprivatemsg", (senderJid, msg) => {
    console.log(`Received message from ${senderJid}`)
})

msg: the received message

Received Private Image
Kik.on("receivedprivateimg", (senderJid, img) => {
    console.log(`Received image from ${senderJid}`)
})

img: a buffer object representing the image

Private Is Typing
Kik.on("privatetyping", (senderJid, isTyping) => {
    if(isTyping){
        console.log(`${senderJid} is typing`)
    }else{
        console.log(`${senderJid} stopped typing`)
    }
})

isTyping: true if the user is typing, false if he stopped

Requests

Note that all callback functions can be excluded

Common Requests

Create Account
Kik.createAccount(email, username, password, firstName, lastName, birthdate, captchaResponse, () => {
    console.log('Account created successfully')
})
Authenticate
Kik.authenticate(usernameOrEmail, password)

If username and password are not provided, the client will use anonymous authentication

Get Roster
Kik.getRoster((groups, friends) => {
    
});

See received roster for response information

Get User Info

This function can be used to search users by username

Kik.getUserInfo(usernamesOrJids, useXiphias, (users) => {
    
});

usernamesOrJids: a single username or a single jid string. Also accepts an array of jid strings or username strings

useXiphias: if true will use the xiphias endpoint. This endpoint accepts jids only and returns different data

useXiphias = true useXiphias = false
username ✔️
displayName ✔️ ✔️
profilePic ✔️
backgroundPic ✔️
registrationTimestamp ✔️
kinId ✔️

note that some data will only be returned if you're chatting with a user

returns an array of user objects, or an empty array if no results are found

Send Message

You can provide a group's or a user's jid, they will automatically use the appropriate format

Kik.sendMessage(jid, msg, (delivered, read) => {
    if(delivered){
        console.log("Delivered")
    }else if(read){
        console.log("Read")
    }
})
Send Image

You can provide a group's or a user's jid, they will automatically use the appropriate format

Kik.sendImage(jid, imgPath, allowForwarding, allowSaving)

allowForwarding: boolean, if false this image will not give the receiver a forwarding option. true by default

allowSaving: boolean, if false this image will not give the receiver a download option. true by default

returns a promise, make sure to use this inside an async function with the await keyword

Add Friend
Kik.addFriend(jid)
Remove Friend
Kik.removeFriend(jid)

Group Requests

Search Groups
Kik.searchGroups(searchQuery, (groups) => {
    
})

groups: an array of group objects representing the search results, the group objects here have a special joinToken variable used for joining the group

Join Group
Kik.joinGroup(groupJid, groupCode, joinToken)
Leave Group
Kik.leaveGroup(groupJid)
Kick/Add
Kik.setGroupMember(groupJid, userJid, bool)
Promote/Demote
Kik.setAdmin(groupJid, userJid, bool)
Ban/Unban
Kik.setBanned(groupJid, userJid, bool)
Change Group Name
Kik.setGroupName(groupJid, name)

Profile Requests

Set Profile Name
Kik.setProfileName(firstName, lastName)
Set Email
Kik.setEmail(newEmail, password)
Set Password
Kik.setPassword(newPassword, oldPassword)

License

GNU AGPLv3