enricostara/telegram.link

View on GitHub
doc/api/messages.html

Summary

Maintainability
Test Coverage
<!DOCTYPE html>

<html>
<head>
  <title>messages.js</title>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
  <link rel="stylesheet" media="all" href="../docco.css" />
</head>
<body>
  <div id="container">
    <div id="background"></div>
    
    <ul class="sections">
        
          <li id="title">
              <div class="annotation">
                  <h1>messages.js</h1>
              </div>
          </li>
        
        
        
        <li id="section-1">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-1">&#182;</a>
              </div>
              <pre><code>telegram.link
Copyright <span class="hljs-number">2014</span> Enrico Stara <span class="hljs-string">'enrico.stara@gmail.com'</span>
Released under the MIT License
http:<span class="hljs-comment">//telegram.link</span>
</code></pre>
            </div>
            
        </li>
        
        
        <li id="section-2">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-2">&#182;</a>
              </div>
              <p>Dependencies:</p>

            </div>
            
            <div class="content"><div class='highlight'><pre><span class="hljs-keyword">var</span> api = <span class="hljs-built_in">require</span>(<span class="hljs-string">'../api'</span>);
<span class="hljs-keyword">var</span> utility = <span class="hljs-built_in">require</span>(<span class="hljs-string">'../utility'</span>);</pre></div></div>
            
        </li>
        
        
        <li id="section-3">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-3">&#182;</a>
              </div>
              <hr>

            </div>
            
        </li>
        
        
        <li id="section-4">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-4">&#182;</a>
              </div>
              <p>This module wraps API methods required to manage the messages.</p>

            </div>
            
        </li>
        
        
        <li id="section-5">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-5">&#182;</a>
              </div>
              <p>See <a href="https://core.telegram.org/methods#working-with-messages">Api Methods</a></p>

            </div>
            
        </li>
        
        
        <li id="section-6">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-6">&#182;</a>
              </div>
              <p>Access only via Client object and <code>messages</code> instance property</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Messages</span>(<span class="hljs-params">client</span>) </span>{
    <span class="hljs-keyword">this</span>.client = client;
}</pre></div></div>
            
        </li>
        
        
        <li id="section-7">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-7">&#182;</a>
              </div>
              <hr>

            </div>
            
        </li>
        
        
        <li id="section-8">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-8">&#182;</a>
              </div>
              <p><strong>Event: </strong><code>&#39;method name&#39;</code></p>

            </div>
            
        </li>
        
        
        <li id="section-9">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-9">&#182;</a>
              </div>
              <p>Each of the following methods emits an event with the same name when done, an <code>error</code> event otherwise.</p>

            </div>
            
        </li>
        
        
        <li id="section-10">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-10">&#182;</a>
              </div>
              <hr>
<p>messages.<strong>getDialogs(offset, max_id, limit, [callback])</strong></p>

            </div>
            
        </li>
        
        
        <li id="section-11">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-11">&#182;</a>
              </div>
              <p>Return a Promise to get the current user dialog list.</p>

            </div>
            
        </li>
        
        
        <li id="section-12">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-12">&#182;</a>
              </div>
              <p><a href="https://core.telegram.org/method/messages.getDialogs">Click here for more details</a></p>

            </div>
            
        </li>
        
        
        <li id="section-13">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-13">&#182;</a>
              </div>
              <p>The code:</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>Messages.prototype.getDialogs = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">offset, max_id, limit, callback</span>) </span>{
    <span class="hljs-keyword">return</span> utility.callService(api.service.messages.getDialogs, <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>
        
        
        <li id="section-14">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-14">&#182;</a>
              </div>
              <hr>
<p>messages.<strong>getHistory(peer, offset, max_id, limit, [callback])</strong></p>

            </div>
            
        </li>
        
        
        <li id="section-15">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-15">&#182;</a>
              </div>
              <p>Return a Promise to get the message history for a chat.</p>

            </div>
            
        </li>
        
        
        <li id="section-16">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-16">&#182;</a>
              </div>
              <p><a href="https://core.telegram.org/method/messages.getHistory">Click here for more details</a></p>

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

            </div>
            
        </li>
        
        
        <li id="section-18">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-18">&#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( ...

 <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>
        
        
        <li id="section-19">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-19">&#182;</a>
              </div>
              <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>
        
        
        <li id="section-20">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-20">&#182;</a>
              </div>
              <hr>
<p>messages.<strong>readHistory(peer, max_id, offset, read_contents, [callback])</strong></p>

            </div>
            
        </li>
        
        
        <li id="section-21">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-21">&#182;</a>
              </div>
              <p>Return a Promise to mark the message history as read..</p>

            </div>
            
        </li>
        
        
        <li id="section-22">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-22">&#182;</a>
              </div>
              <p><a href="https://core.telegram.org/method/messages.readHistory">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>The code:</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>Messages.prototype.readHistory = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">peer, max_id, offset, read_contents, callback</span>) </span>{

    read_contents = read_contents === <span class="hljs-literal">false</span> ? <span class="hljs-keyword">new</span> api.type.BoolFalse() :
        ( read_contents === <span class="hljs-literal">true</span> ? <span class="hljs-keyword">new</span> api.type.BoolTrue() : read_contents);

    <span class="hljs-keyword">return</span> utility.callService(api.service.messages.readHistory, <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>
        
        
        <li id="section-24">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-24">&#182;</a>
              </div>
              <hr>
<p>messages.<strong>sendMessage(peer, message, random_id, [callback])</strong></p>

            </div>
            
        </li>
        
        
        <li id="section-25">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-25">&#182;</a>
              </div>
              <p>Return a Promise to send a message to the peer.</p>

            </div>
            
        </li>
        
        
        <li id="section-26">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-26">&#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-27">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-27">&#182;</a>
              </div>
              <p>Usage example (<code>user_id</code> must be a real contact id, of course):</p>

            </div>
            
        </li>
        
        
        <li id="section-28">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-28">&#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( ...

 <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.sendMessage(
      peer,
      <span class="hljs-string">'My UTF8 first msg!!'</span>,
      <span class="hljs-number">9876543211</span>  <span class="hljs-comment">// random id...</span>
 ).then(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">sentMsg</span>) </span>{
      <span class="hljs-built_in">console</span>.log(<span class="hljs-string">'sentMsg:'</span>, sentMsg.toPrintable());
 });
</code></pre>
            </div>
            
        </li>
        
        
        <li id="section-29">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-29">&#182;</a>
              </div>
              <p>The code:</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>Messages.prototype.sendMessage = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">peer, message, random_id, callback</span>) </span>{
    <span class="hljs-keyword">return</span> utility.callService(api.service.messages.sendMessage, <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>
        
        
        <li id="section-30">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-30">&#182;</a>
              </div>
              <p>Export the class.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre><span class="hljs-built_in">module</span>.exports = exports = Messages;</pre></div></div>
            
        </li>
        
    </ul>
  </div>
</body>
</html>