twitch-toolkit
Version:
A set of tools to integrate with Twitch API, Twitch Chat and Twitch WebHooks.
1,685 lines (505 loc) • 25.8 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>TwitchWebhook - Documentation</title>
<script src="scripts/prettify/prettify.js"></script>
<script src="scripts/prettify/lang-css.js"></script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
<label for="nav-trigger" class="navicon-button x">
<div class="navicon"></div>
</label>
<label for="nav-trigger" class="overlay"></label>
<nav>
<li class="nav-link nav-home-link"><a href="index.html">Home</a></li><li class="nav-heading">Classes</li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="TwitchApi.html">TwitchApi</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchApi.html#getAccessToken">getAccessToken</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchApi.html#getGames">getGames</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchApi.html#getStreams">getStreams</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchApi.html#getStreamsMetadata">getStreamsMetadata</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchApi.html#getUsers">getUsers</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchApi.html#getUsersFollows">getUsersFollows</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchApi.html#getVideos">getVideos</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchApi.html#isLive">isLive</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchApi.html#updateUser">updateUser</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchApi.html#validateAccessToken">validateAccessToken</a></span></li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="TwitchChatEmitter.html">TwitchChatEmitter</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchChatEmitter.html#connect">connect</a></span></li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="TwitchPubSub.html">TwitchPubSub</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchPubSub.html#connect">connect</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchPubSub.html#disconnect">disconnect</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchPubSub.html#reconnect">reconnect</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchPubSub.html#subscribe">subscribe</a></span></li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="TwitchWebhook.html">TwitchWebhook</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchWebhook.html#destroy">destroy</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchWebhook.html#handleRequest">handleRequest</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchWebhook.html#subscribe">subscribe</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchWebhook.html#topicStreamUpDownSubscribe">topicStreamUpDownSubscribe</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchWebhook.html#topicUserFollowsSubscribe">topicUserFollowsSubscribe</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchWebhook.html#unsubscribe">unsubscribe</a></span></li><li class="nav-heading">Events</li><li class="nav-heading"><span class="nav-item-type type-event">E</span><span class="nav-item-name"><a href="TwitchChatEmitter.html#event:Chat:chat_parsed">Chat:chat_parsed</a></span></li><li class="nav-heading"><span class="nav-item-type type-event">E</span><span class="nav-item-name"><a href="TwitchWebhook.html#event:Webhook:stream_up_down">Webhook:stream_up_down</a></span></li><li class="nav-heading"><span class="nav-item-type type-event">E</span><span class="nav-item-name"><a href="TwitchWebhook.html#event:Webhook:user_follows">Webhook:user_follows</a></span></li>
</nav>
<div id="main">
<h1 class="page-title">TwitchWebhook</h1>
<section>
<header>
<h2>
TwitchWebhook
</h2>
<div class="class-description"><p>TwitchWebhook
The Twitch Webhooks implementation, as described in https://dev.twitch.tv/docs/api/webhooks-guide/ .
The Webhook requires a public endpoint on the running express server/application to receive the data from the hub. Without this, its impossible to make this work.</p></div>
</header>
<article>
<div class="container-overview">
<div class="section-method">
<h2>Constructor</h2>
<h4 class="name" id="TwitchWebhook"><span class="type-signature"></span>new TwitchWebhook<span class="signature">(config)</span><span class="type-signature"></span></h4>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="twitchWebhook.js.html">twitchWebhook.js</a>, <a href="twitchWebhook.js.html#line21">line 21</a>
</li></ul></dd>
</dl>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>config</code></td>
<td class="type">
<span class="param-type"><code>object</code></span>
</td>
<td class="description last">
<p>The config object.</p>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>clientId</code></td>
<td class="type">
<span class="param-type"><code>string</code></span>
</td>
<td class="description last">
<p>The client ID of the user to be passed to the Hub (un)subscribe requests. This is required.</p>
</td>
</tr>
<tr>
<td class="name"><code>callbackUrl</code></td>
<td class="type">
<span class="param-type"><code>string</code></span>
</td>
<td class="description last">
<p>The callback URL that will receive the Hub requests. These requests should be forwarded to the handleRequest method to properly handle these data. This is required.</p>
</td>
</tr>
<tr>
<td class="name"><code>logger</code></td>
<td class="type">
<span class="param-type"><code>object</code></span>
</td>
<td class="description last">
<p>The logger object.</p>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<h3 class="subsection-title">Methods</h3>
<div class="section-method">
<h4 class="name" id="destroy"><span class="type-signature"></span>destroy<span class="signature">()</span><span class="type-signature"></span></h4>
<div class="description">
<p>Destroy the Webhook, unsubscribing every active subscription.</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="twitchWebhook.js.html">twitchWebhook.js</a>, <a href="twitchWebhook.js.html#line194">line 194</a>
</li></ul></dd>
</dl>
</div>
<div class="section-method">
<h4 class="name" id="handleRequest"><span class="type-signature"></span>handleRequest<span class="signature">(method, headers, qs, body)</span><span class="type-signature"> → {object}</span></h4>
<div class="description">
<p>This method will handle the request data and validate the subscriptions or properly emit the events with the received data.</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="twitchWebhook.js.html">twitchWebhook.js</a>, <a href="twitchWebhook.js.html#line137">line 137</a>
</li></ul></dd>
</dl>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>method</code></td>
<td class="type">
<span class="param-type"><code>string</code></span>
</td>
<td class="description last">
<p>The http method</p>
</td>
</tr>
<tr>
<td class="name"><code>headers</code></td>
<td class="type">
<span class="param-type"><code>Array.<string></code></span>
</td>
<td class="description last">
<p>The headers array</p>
</td>
</tr>
<tr>
<td class="name"><code>qs</code></td>
<td class="type">
<span class="param-type"><code>Array.<string></code></span>
</td>
<td class="description last">
<p>The request query string array. Used for GET and POST</p>
</td>
</tr>
<tr>
<td class="name"><code>body</code></td>
<td class="type">
<span class="param-type"><code>Array.<string></code></span>
</td>
<td class="description last">
<p>The POST body. Used just for post.</p>
</td>
</tr>
</tbody>
</table>
<div class="section-returns">
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type:
</dt>
<dd>
<span class="param-type"><code>object</code></span>
</dd>
</dl>
<div class="param-desc">
<p>The response result object with the status and data to be sent in the response.</p>
</div>
</div>
</div>
<div class="section-method">
<h4 class="name" id="subscribe"><span class="type-signature"></span>subscribe<span class="signature">(topic, eventName)</span><span class="type-signature"> → {Promise}</span></h4>
<div class="description">
<p>Subscribe to a specific topic that will fires an event when new data is received from the hub.
The event handler will receive the data object and the subscription ID.</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="twitchWebhook.js.html">twitchWebhook.js</a>, <a href="twitchWebhook.js.html#line92">line 92</a>
</li></ul></dd>
</dl>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>topic</code></td>
<td class="type">
<span class="param-type"><code>string</code></span>
</td>
<td class="description last">
<p>The topic name/URL.</p>
</td>
</tr>
<tr>
<td class="name"><code>eventName</code></td>
<td class="type">
<span class="param-type"><code>string</code></span>
</td>
<td class="description last">
<p>The event name that will be fired when new data is received.</p>
</td>
</tr>
</tbody>
</table>
<div class="section-returns">
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type:
</dt>
<dd>
<span class="param-type"><code>Promise</code></span>
</dd>
</dl>
<div class="param-desc">
<p>The subscription promise that will be resolved when it receives the response. It will return the connection ID.</p>
</div>
</div>
</div>
<div class="section-method">
<h4 class="name" id="topicStreamUpDownSubscribe"><span class="type-signature"></span>topicStreamUpDownSubscribe<span class="signature">(streamUserId)</span><span class="type-signature"> → {string}</span></h4>
<div class="description">
<p>Notifies when a stream goes online or offline. The response mimics the Get Streams endpoint. (https://dev.twitch.tv/docs/api/reference/#get-streams)</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="twitchWebhook.js.html">twitchWebhook.js</a>, <a href="twitchWebhook.js.html#line68">line 68</a>
</li></ul></dd>
</dl>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>streamUserId</code></td>
<td class="type">
<span class="param-type"><code>number</code></span>
</td>
<td class="description last">
<p>The ID of the user whose stream is monitored.</p>
</td>
</tr>
</tbody>
</table>
<h5>Fires:</h5>
<ul>
<li><a href="TwitchWebhook.html#event:Webhook:stream_up_down">TwitchWebhook#Webhook:stream_up_down</a></li>
</ul>
<div class="section-returns">
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type:
</dt>
<dd>
<span class="param-type"><code>string</code></span>
</dd>
</dl>
<div class="param-desc">
<p>The subscription ID, used to identify the active topic.</p>
</div>
</div>
</div>
<div class="section-method">
<h4 class="name" id="topicUserFollowsSubscribe"><span class="type-signature"></span>topicUserFollowsSubscribe<span class="signature">(fromId, toId)</span><span class="type-signature"> → {string}</span></h4>
<div class="description">
<p>Notifies when a follows event occurs. The response mimics the Get Users Follows endpoint. (https://dev.twitch.tv/docs/api/reference/#get-users-follows)</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="twitchWebhook.js.html">twitchWebhook.js</a>, <a href="twitchWebhook.js.html#line38">line 38</a>
</li></ul></dd>
</dl>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>fromId</code></td>
<td class="type">
<span class="param-type"><code>number</code></span>
</td>
<td class="description last">
<p>The ID of the user who starts following someone.</p>
</td>
</tr>
<tr>
<td class="name"><code>toId</code></td>
<td class="type">
<span class="param-type"><code>number</code></span>
</td>
<td class="description last">
<p>The ID of the user who has a new follower.</p>
</td>
</tr>
</tbody>
</table>
<h5>Fires:</h5>
<ul>
<li><a href="TwitchWebhook.html#event:Webhook:user_follows">TwitchWebhook#Webhook:user_follows</a></li>
</ul>
<div class="section-returns">
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type:
</dt>
<dd>
<span class="param-type"><code>string</code></span>
</dd>
</dl>
<div class="param-desc">
<p>The subscription ID, used to identify the active topic.</p>
</div>
</div>
</div>
<div class="section-method">
<h4 class="name" id="unsubscribe"><span class="type-signature"></span>unsubscribe<span class="signature">(id)</span><span class="type-signature"> → {Promise}</span></h4>
<div class="description">
<p>Unsubscribe from a topic by its ID.</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="twitchWebhook.js.html">twitchWebhook.js</a>, <a href="twitchWebhook.js.html#line157">line 157</a>
</li></ul></dd>
</dl>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>id</code></td>
<td class="type">
<span class="param-type"><code>string</code></span>
</td>
<td class="description last">
<p>The subscription ID.</p>
</td>
</tr>
</tbody>
</table>
<div class="section-returns">
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type:
</dt>
<dd>
<span class="param-type"><code>Promise</code></span>
</dd>
</dl>
<div class="param-desc">
<p>The subscription promise that will be resolved when it receives the response.</p>
</div>
</div>
</div>
<h3 class="subsection-title">Events</h3>
<div class="section-method">
<h4 class="name" id="event:Webhook:stream_up_down">Webhook:stream_up_down</h4>
<div class="description">
<p>Stream Up/Down Event</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="twitchWebhook.js.html">twitchWebhook.js</a>, <a href="twitchWebhook.js.html#line71">line 71</a>
</li></ul></dd>
</dl>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>data</code></td>
<td class="type">
<span class="param-type"><code>object</code></span>
</td>
<td class="description last">
<p>The data object received from the Hub.</p>
</td>
</tr>
<tr>
<td class="name"><code>id</code></td>
<td class="type">
<span class="param-type"><code>string</code></span>
</td>
<td class="description last">
<p>The subscription ID.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="section-method">
<h4 class="name" id="event:Webhook:user_follows">Webhook:user_follows</h4>
<div class="description">
<p>Stream User Follows Event</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="twitchWebhook.js.html">twitchWebhook.js</a>, <a href="twitchWebhook.js.html#line42">line 42</a>
</li></ul></dd>
</dl>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>data</code></td>
<td class="type">
<span class="param-type"><code>object</code></span>
</td>
<td class="description last">
<p>The data object received from the Hub.</p>
</td>
</tr>
<tr>
<td class="name"><code>id</code></td>
<td class="type">
<span class="param-type"><code>string</code></span>
</td>
<td class="description last">
<p>The subscription ID.</p>
</td>
</tr>
</tbody>
</table>
</div>
</article>
</section>
</div>
<br class="clear">
<footer>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Mon Nov 12 2018 18:32:59 GMT-0200 (E. South America Daylight Time) using the Minami theme.
</footer>
<script>prettyPrint();</script>
<script src="scripts/linenumber.js"></script>
</body>
</html>