Skip to content

Commit

Permalink
Add the usage example for messages.getHistory
Browse files Browse the repository at this point in the history
  • Loading branch information
enricostara committed Aug 11, 2015
1 parent 2fa1eb1 commit c063d99
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 14 deletions.
70 changes: 56 additions & 14 deletions doc/messages.html
Original file line number Diff line number Diff line change
Expand Up @@ -252,14 +252,10 @@ <h1>messages.js</h1>
<div class="pilwrap ">
<a class="pilcrow" href="#section-17">&#182;</a>
</div>
<p>The code:</p>
<p>Usage example (<code>user_id</code> must be a real contact id, of course):</p>

</div>

<div class="content"><div class='highlight'><pre>Messages.prototype.getHistory = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">peer, offset, max_id, limit, callback</span>) </span>{
<span class="hljs-keyword">return</span> utility.callService(api.service.messages.getHistory, <span class="hljs-keyword">this</span>.client, <span class="hljs-keyword">this</span>.client._channel, callback, <span class="hljs-built_in">arguments</span>);
};</pre></div></div>

</li>


Expand All @@ -269,9 +265,24 @@ <h1>messages.js</h1>
<div class="pilwrap ">
<a class="pilcrow" href="#section-18">&#182;</a>
</div>
<hr>
<p>messages.<strong>sendMessage(peer, message, random_id, [callback])</strong></p>
<pre><code> <span class="hljs-keyword">var</span> api = <span class="hljs-built_in">require</span>(<span class="hljs-string">'telegram.link'</span>)();

<span class="hljs-keyword">var</span> client = api.createClient( ...

<span class="hljs-keyword">var</span> peer = <span class="hljs-keyword">new</span> api.type.InputPeerContact({
props: {
user_id: <span class="hljs-number">12345678</span>
}
});

client.messages.getHistory(
peer,
<span class="hljs-number">0</span>, <span class="hljs-number">0</span>,
<span class="hljs-number">10</span> <span class="hljs-comment">// num of messages to be returned</span>
).then(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">messages</span>) </span>{
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">'messages:'</span>, messages.toPrintable());
});
</code></pre>
</div>

</li>
Expand All @@ -283,10 +294,14 @@ <h1>messages.js</h1>
<div class="pilwrap ">
<a class="pilcrow" href="#section-19">&#182;</a>
</div>
<p>Returns a Promise for get the message history for a chat.</p>
<p>The code:</p>

</div>

<div class="content"><div class='highlight'><pre>Messages.prototype.getHistory = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">peer, offset, max_id, limit, callback</span>) </span>{
<span class="hljs-keyword">return</span> utility.callService(api.service.messages.getHistory, <span class="hljs-keyword">this</span>.client, <span class="hljs-keyword">this</span>.client._channel, callback, <span class="hljs-built_in">arguments</span>);
};</pre></div></div>

</li>


Expand All @@ -296,7 +311,8 @@ <h1>messages.js</h1>
<div class="pilwrap ">
<a class="pilcrow" href="#section-20">&#182;</a>
</div>
<p><a href="https://core.telegram.org/method/messages.sendMessage">Click here for more details</a></p>
<hr>
<p>messages.<strong>sendMessage(peer, message, random_id, [callback])</strong></p>

</div>

Expand All @@ -309,7 +325,7 @@ <h1>messages.js</h1>
<div class="pilwrap ">
<a class="pilcrow" href="#section-21">&#182;</a>
</div>
<p>Usage example (<code>user_id</code> must be a real contact id, of course):</p>
<p>Returns a Promise for get the message history for a chat.</p>

</div>

Expand All @@ -322,6 +338,32 @@ <h1>messages.js</h1>
<div class="pilwrap ">
<a class="pilcrow" href="#section-22">&#182;</a>
</div>
<p><a href="https://core.telegram.org/method/messages.sendMessage">Click here for more details</a></p>

</div>

</li>


<li id="section-23">
<div class="annotation">

<div class="pilwrap ">
<a class="pilcrow" href="#section-23">&#182;</a>
</div>
<p>Usage example (<code>user_id</code> must be a real contact id, of course):</p>

</div>

</li>


<li id="section-24">
<div class="annotation">

<div class="pilwrap ">
<a class="pilcrow" href="#section-24">&#182;</a>
</div>
<pre><code> <span class="hljs-keyword">var</span> api = <span class="hljs-built_in">require</span>(<span class="hljs-string">'telegram.link'</span>)();

<span class="hljs-keyword">var</span> client = api.createClient( ...
Expand All @@ -345,11 +387,11 @@ <h1>messages.js</h1>
</li>


<li id="section-23">
<li id="section-25">
<div class="annotation">

<div class="pilwrap ">
<a class="pilcrow" href="#section-23">&#182;</a>
<a class="pilcrow" href="#section-25">&#182;</a>
</div>
<p>The code:</p>

Expand All @@ -362,11 +404,11 @@ <h1>messages.js</h1>
</li>


<li id="section-24">
<li id="section-26">
<div class="annotation">

<div class="pilwrap ">
<a class="pilcrow" href="#section-24">&#182;</a>
<a class="pilcrow" href="#section-26">&#182;</a>
</div>
<p>Exports the class.</p>

Expand Down
20 changes: 20 additions & 0 deletions lib/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,26 @@ Messages.prototype.getDialogs = function (offset, max_id, limit, callback) {

// [Click here for more details](https://core.telegram.org/method/messages.getHistory)

// Usage example (`user_id` must be a real contact id, of course):

// var api = require('telegram.link')();
//
// var client = api.createClient( ...
//
// var peer = new api.type.InputPeerContact({
// props: {
// user_id: 12345678
// }
// });
//
// client.messages.getHistory(
// peer,
// 0, 0,
// 10 // num of messages to be returned
// ).then(function(messages) {
// console.log('messages:', messages.toPrintable());
// });

// The code:
Messages.prototype.getHistory = function (peer, offset, max_id, limit, callback) {
return utility.callService(api.service.messages.getHistory, this.client, this.client._channel, callback, arguments);
Expand Down

0 comments on commit c063d99

Please sign in to comment.