npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

chatwork-api

v1.0.0

Published

Chatwork API for JavaScript

Downloads

4

Readme

chatwork-api

A JavaScript wrapper for Chatwork APIs.

Current Version: v1.0 Preview

Install

$ npm i -S chatwork-api

Usage

2 main functions:

  • Message Builder: Utility for build chat message easier
  • Chatwork API caller: Call Chatwork API

Message Builder

Utility for build chat message easier.

Builder(message, roomId)

Create a new MessageBuilder instance with initial message and chat room id.

builder.toString()

Get current message.

builder.message

Get current messsge. Same as toString()

builder.message=

Set current message.

builder.n(number)

Append number of new lines. Default is 1 line.

builder.append(message)

Append message.

builder.prepend(message)

Prepend message.

builder.to(account_id)

Send message to account_id, then append to current message.

builder.reply(account_id, message_id, room_id)

Reply to account_id with message has id message_id in room room_id, then append to current message. Default of room_id is instance.room_id

builder.quote(account_id, message, timestamp)

Quote message of account_id at timestamp, then append to current message. timestamp is optional.

builder.info(message, title)

Wrap info for message with title, then append to current message. title is optional.

builder.hr()

Wrap hr, then append to current message.

builder.profileIcon(account_id, is_include_name)

Show profile icon for account_id, then append to current message. When is_include_name is true, this will show both of profile icon and profile name. The default is false.

Chatwork APIs

The wrapper for Chatwork APIs.

  • The options for each request is same as Chatwork API options. This reduces the maintain of this lib.
API(token, options)

Create new API instance with token, and request options.

api.request

Get the current request object.

api.token

Get current Chatwork api token.

api.token=

Set Chatwork api token

api.set(token, options)

Set Chatwork api token, and request options.

api.me()

Get my profile.

api.myStatus()

Get current status.

api.myTasks(aid, status)

Get my tasks.

api.contacts()

Get my contacts.

api.rooms()

Get my list chat rooms.

api.createRoom(options)

Create a new chat room.

options: {
  description,         // room description
  icon_preset,         // room icon. Default is `group`
  name,                // room name
  members_admin_ids,   // list of admin member ids [Integer, String, Array]
  members_member_ids,  // list of normal member ids [Integer, String, Array]
  members_readonly_ids // list of readonly member ids [Integer, String, Array]
}
api.room(room_id)

Get chat room detail.

api.updateRoom(room_id, options)

Update chat room information.

options: {
  description, // room description
  icon_preset, // room icon. Default is `group`
  name         // room name
}
api.exitRoom(room_id)

Leave chat room.

api.delRoom(room_id)

Delete chat room.

api.members(room_id)

Get list members of a chat room.

api.updateMembers(room_id, options)

Update list of members for a chat room.

options: {
  members_admin_ids,   // list of admin member ids [Integer, String, Array]
  members_member_ids,  // list of normal member ids [Integer, String, Array]
  members_readonly_ids // list of readonly member ids [Integer, String, Array]
}
api.messages(room_id, force)

Get list messages.

api.message(room_id, message_id)

Get message information.

api.sendMessage(room_id, body)

Send a new message.

api.tasks(room_id, options)

Get list taks.

options: {
  account_id,              // owner account id
  assigned_by_account_id,  // assigned account id
  status                   // task content. Default is `open`
}
api.task (room_id, task_id)

Get task information.

api.createTask(room_id, options)

Create a new task.

options: {
  body,  // task content
  limit, // task expiration
  to_ids // assign to list of account_ids. [Integer, String, Array]
}
api.files(room_id, uploaded_account_id)

Get list files.

api.file(room_id, file_id, doCreateDownloadUrl)

Get file information. Default of doCreateDownloadUrl is false.

Examples

const API = require('chatwork-api', {
  proxy: 'http://USER_NAME:USER_PASS@PROXY_URL:PROXY_PORT/'
})
const MessageBuilder = API.MessageBuilder
const STATUS = API.CONST.STATUS

// create new API instance with api token
let api = new API('YOUR_TOKEN_HERE')

// get my task
api.myTasks('ASSIGNED_BY_ACCOUNT_ID', STATUS.DONE)
  .then(console.log)
  .catch(console.error)

// create a new message with MessageBuilder
let builder = new MessageBuilder()
builder.to('ACCOUNT_ID')      // send to ACCOUNT_ID
  .append('Wellcome to this') // append message
  .append('世界')
builder.n(2)                       // add 2 new lines
  .append('Awesome ')
  .profileIcon('ACCOUNT_ID', true) // add profile icon with user name
// send message in ROOM_ID
api.sendMessage('ROOM_ID', builder.message)
  .then(console.log)
  .catch(console.error)