This is documentation for the upcoming version (9.2), which is still in development. Content may change before release.

See the same page for the current release.

Plugins

About the plugin feature built into OneComme

OneComme (5.2 and later) includes a plugin mechanism that runs on JavaScript (Node.js).

Development --

Using console outputs to plugin.log in the log file.

console.info("Hello OneComme!");

Sample

OneComme sample plugin and template

https://github.com/OneComme/OneCommeOrderSpeechPlugin

OneComme comment filter sample plugin

https://github.com/OneComme/OneCommeFilterSamplePlugin

※ The sample plugins can be freely modified and redistributed

Overall code structure

const plugin = {  
  name: 'Sample Plugin', // @required plugin name  
  uid: 'com.onecoome.sampleplugin', // @required unique plugin id  
  version: '0.0.1', // @required semver version  
  author: 'OneComme', // @required author name  
  url: 'https://onecomme.com', // @optional link (ex. documentation link)  
  permissions: ['comments'], // @required https://onecomme.com/docs/developer/websocket-api/#%E3%82%A4%E3%83%99%E3%83%B3%E3%83%88%E3%81%AE%E7%A8%AE%E9%A1%9E%E3%81%A8%E3%83%87%E3%83%BC%E3%82%BF  
  defaultState: { // @optional key-value custom state  
	  count: 0  
  },  
  /**  
   *   
   * @param { dir: string, filepath: string, store: ElectronStore} param  
   * dir: plugin directory path  
   * filepath: this script's path  
   * store: ElectronStore Instance  https://github.com/sindresorhus/electron-store?tab=readme-ov-file#instance  
   */  
  init({ dir, store }, initialData) {},  
  /**  
   * called on exit or when activated  
   * @optional  
   */  
  destroy() {},  
  /**  
   * called when the event specified in permissions occurs ( exclude connected event )  
   * @optional  
   * https://onecomme.com/docs/developer/websocket-api  
   */  
  subscribe(type, ...args) {  
    switch (type) {  
      case 'comments': {  
          
      }  
    }  
  },  
	/**  
   * filter comment  
   * @param {Comment} Comment   
   * @param {Service} Service   
   * @param {UserNameData | null} UserData   
   * @returns Promise  
   */  
  filterComment(comment, service, userData) {  
	  if (comment.service === 'sample') return false  
    return comment  
  },  
  /**  
   * filter speech  
   * @param {string} text  
   * @param {UserNameData | null} userData  
   * @param {SpeechConfig} config  
   * @param optional {Comment} comment  
   * @returns Promise  
   */  
  filterSpeech(text, userData, config, comment) {  
	  if (!userData) return false  
    return text  
  },  
  /**  
   * called when a request is made to the plugin-specific RestAPI  
   * @param {  
   *   url: string // request url  
   *   method: 'GET' | 'POST' | 'PUT' | 'DELETE'  
   *   params: {[key: string]: string} // querystrings  
   *   body?: any // request body  
   * } req  
   * @returns {  
   *   code: number // status code  
   *   response: Object or Array // response data  
   * }  
   */  
  async request(req: PluginRequest) {  
    // [GET, POST, PUT, DELETE]  
    // endpoint: localhost:11180/api/plugins/com.onecomme.plugin-sample  
    switch (req.method) {  
      case 'GET': {}  
      case 'POST': {}  
      case 'PUT': {}  
      case 'DELETE': {}  
    }  
    return {  
      code: 404,  
      response: {}  
    }  
  }  
}  
module.exports = plugin

Plugin type information

nameRequiredThe name of the plugin
uidRequiredA unique ID for the plugin. It must not duplicate the ID of any other plugin
versionRequiredThe version number of the plugin itself
authorRequiredThe name of the plugin developer
urlIf set, a button to open this link appears on OneComme's plugin page (link to a settings or manual page)
permissionsRequiredSpecify, as an array, the data types used by the plugin
Data not listed here cannot be retrieved
For a list of available values and the data you can receive, see Permission in the Templates SDK (comments, reactions, events, etc.)
In addition to these, the plugin-specific values 'filter.comment' and 'filter.speech' can also be specified
defaultStateDefines the initial values of the data held by the plugin
The state is persisted as a JSON file via the store
init({ dir, store },initialData):voidRuns when the plugin is enabled, and when OneComme starts while the plugin is enabled
dir: the plugin directory path
store: an instance of ElectronStore
destroy():voidRuns when the plugin is disabled, and when OneComme exits while the plugin is enabled
subscribe(type: SendType, …args: any[])Runs when data specified in permissions is received
※ The arguments after the second one vary depending on the data type
filterComment(comment: Comment, service: Service, userData: UserData): Promise<Comment | boolean>Runs when a comment is received; by returning comment data you can return a modified comment, etc., to OneComme
If you return false, the comment is filtered out
※ You must specify 'filter.comment' in permissions
filterSpeech(text: string, userData: UserNameData, config: SpeechConfig, comment?: Comment ): Promise<string | boolean>Runs before speech playback; by returning the speech string you can have the modified text spoken
If you return false, speech is suppressed
※ You must specify 'filter.speech' in permissions
※ Note that comment may not be included, such as when sent directly via the speech API
request(req: PluginRequest): Promise< PluginResponse >Runs when a request to the RestAPI provided for each plugin is received
Used for saving data to the plugin from a settings screen, etc., or for receiving data stored in the plugin
※ See the plugin RestAPI section below

Plugin RestAPI

When a plugin is enabled, OneComme provides a RestAPI to the plugin.
You can send GET/POST/PUT/DELETE requests to http://localhost:11180/api/plugins/$\{PLUGIN_UID\}.

Requests are sent to the plugin's request function.

Request-side sample: https://github.com/OneComme/OneCommeOrderSpeechPlugin/blob/main/static/script.js

Receiving-side sample: https://github.com/OneComme/OneCommeOrderSpeechPlugin/blob/main/src/index.ts