2015-07-02 21:49:36 +00:00
'use strict' ;
2016-03-27 20:29:00 +00:00
Object . defineProperty ( exports , "__esModule" , {
2015-07-02 21:49:36 +00:00
value : true
} ) ;
2016-03-27 20:29:00 +00:00
var _slicedToArray = function ( ) { function sliceIterator ( arr , i ) { var _arr = [ ] ; var _n = true ; var _d = false ; var _e = undefined ; try { for ( var _i = arr [ Symbol . iterator ] ( ) , _s ; ! ( _n = ( _s = _i . next ( ) ) . done ) ; _n = true ) { _arr . push ( _s . value ) ; if ( i && _arr . length === i ) break ; } } catch ( err ) { _d = true ; _e = err ; } finally { try { if ( ! _n && _i [ "return" ] ) _i [ "return" ] ( ) ; } finally { if ( _d ) throw _e ; } } return _arr ; } return function ( arr , i ) { if ( Array . isArray ( arr ) ) { return arr ; } else if ( Symbol . iterator in Object ( arr ) ) { return sliceIterator ( arr , i ) ; } else { throw new TypeError ( "Invalid attempt to destructure non-iterable instance" ) ; } } ; } ( ) ;
2015-07-02 22:33:22 +00:00
2016-03-27 20:29:00 +00:00
var _createClass = function ( ) { function defineProperties ( target , props ) { for ( var i = 0 ; i < props . length ; i ++ ) { var descriptor = props [ i ] ; descriptor . enumerable = descriptor . enumerable || false ; descriptor . configurable = true ; if ( "value" in descriptor ) descriptor . writable = true ; Object . defineProperty ( target , descriptor . key , descriptor ) ; } } return function ( Constructor , protoProps , staticProps ) { if ( protoProps ) defineProperties ( Constructor . prototype , protoProps ) ; if ( staticProps ) defineProperties ( Constructor , staticProps ) ; return Constructor ; } ; } ( ) ;
2015-07-02 21:49:36 +00:00
var _Base2 = require ( './Base' ) ;
var _Base3 = _interopRequireDefault ( _Base2 ) ;
var _mime = require ( 'mime' ) ;
var _mime2 = _interopRequireDefault ( _mime ) ;
2016-03-27 20:29:00 +00:00
function _interopRequireDefault ( obj ) { return obj && obj . _ _esModule ? obj : { default : obj } ; }
function _classCallCheck ( instance , Constructor ) { if ( ! ( instance instanceof Constructor ) ) { throw new TypeError ( "Cannot call a class as a function" ) ; } }
function _possibleConstructorReturn ( self , call ) { if ( ! self ) { throw new ReferenceError ( "this hasn't been initialised - super() hasn't been called" ) ; } return call && ( typeof call === "object" || typeof call === "function" ) ? call : self ; }
function _inherits ( subClass , superClass ) { if ( typeof superClass !== "function" && superClass !== null ) { throw new TypeError ( "Super expression must either be null or a function, not " + typeof superClass ) ; } subClass . prototype = Object . create ( superClass && superClass . prototype , { constructor : { value : subClass , enumerable : false , writable : true , configurable : true } } ) ; if ( superClass ) Object . setPrototypeOf ? Object . setPrototypeOf ( subClass , superClass ) : subClass . _ _proto _ _ = superClass ; }
2015-07-02 21:49:36 +00:00
var TYPES = [ 'photo' , 'video' , 'document' , 'audio' ] ;
/ * *
* File class , used to send pictures / movies / audios / documents to chat
* /
2016-03-27 20:29:00 +00:00
var File = function ( _Base ) {
_inherits ( File , _Base ) ;
2015-07-02 21:49:36 +00:00
/ * *
* Create a new file instance
* @ param { object } properties File properties , as defined by Telegram API
* /
function File ( ) {
2016-03-27 20:29:00 +00:00
var properties = arguments . length <= 0 || arguments [ 0 ] === undefined ? { } : arguments [ 0 ] ;
2015-07-02 21:49:36 +00:00
_classCallCheck ( this , File ) ;
2016-03-27 20:29:00 +00:00
var _this = _possibleConstructorReturn ( this , Object . getPrototypeOf ( File ) . call ( this , 'sendDocument' ) ) ;
2015-07-02 21:49:36 +00:00
2016-03-27 20:29:00 +00:00
_this . properties = properties ;
_this . _keyboard = new _Base3 . default ( ) ;
return _this ;
2015-07-02 21:49:36 +00:00
}
2016-03-27 20:29:00 +00:00
/ * *
* Set chat _id of the message
* @ param { number } chat
* @ return { object } returns the message object
* /
2015-07-02 21:49:36 +00:00
_createClass ( File , [ {
key : 'to' ,
value : function to ( chat ) {
this . properties . chat _id = chat ;
return this ;
}
/ * *
* Set file of the message
2015-07-02 22:33:22 +00:00
* @ param { string } file File path
2015-07-02 21:49:36 +00:00
* @ param { string } fileType ( optional ) if the first argument is a
* file _id string , this option indicates file type
* @ return { object } returns the message object
* /
2016-03-27 20:29:00 +00:00
} , {
key : 'file' ,
2015-07-02 22:33:22 +00:00
value : function file ( _file , fileType ) {
if ( fileType ) {
2015-07-06 00:05:25 +00:00
this . properties [ fileType ] = { file : _file } ;
2015-07-02 22:33:22 +00:00
return this ;
2015-07-02 21:49:36 +00:00
}
2016-03-27 20:29:00 +00:00
var _mime$lookup$split = _mime2 . default . lookup ( _file ) . split ( '/' ) ;
2015-07-02 22:33:22 +00:00
var _mime$lookup$split2 = _slicedToArray ( _mime$lookup$split , 2 ) ;
var type = _mime$lookup$split2 [ 0 ] ;
var extension = _mime$lookup$split2 [ 1 ] ;
2015-07-02 21:49:36 +00:00
if ( type === 'image' ) {
type = 'photo' ;
}
2015-07-02 22:33:22 +00:00
if ( extension === 'gif' ) {
type = 'document' ;
}
2015-07-02 21:49:36 +00:00
if ( TYPES . indexOf ( type ) === - 1 ) {
type = 'document' ;
}
2015-07-06 00:05:25 +00:00
this . properties [ type ] = { file : _file } ;
2015-07-02 22:33:22 +00:00
this . method = 'send' + ( type [ 0 ] . toUpperCase ( ) + type . slice ( 1 ) ) ;
2015-07-02 21:49:36 +00:00
return this ;
}
/ * *
* Set caption for photos
* @ param { string } text caption ' s text
* @ return { object } returns the message object
* /
2016-03-27 20:29:00 +00:00
} , {
key : 'caption' ,
2015-07-02 21:49:36 +00:00
value : function caption ( text ) {
this . properties . caption = text ;
return this ;
}
/ * *
* Set reply _to _message _id of the message
* @ param { number } id message _id of the message to reply to
* @ return { object } returns the message object
* /
2016-03-27 20:29:00 +00:00
} , {
key : 'reply' ,
2015-07-02 21:49:36 +00:00
value : function reply ( id ) {
this . properties . reply _to _message _id = id ;
return this ;
}
/ * *
* Sets keyboard of the message
* The value of reply _markup is set to the sanitized keyboard properties
* i . e . reply _markup = JSON . stringify ( kb . getProperties ( ) )
* @ param { object } kb A Keyboard instance
* @ return { object } returns the message object
* /
2016-03-27 20:29:00 +00:00
} , {
key : 'keyboard' ,
2015-07-02 21:49:36 +00:00
value : function keyboard ( kb ) {
this . _keyboard = kb ;
return this ;
}
// This class inherits Base's send method
} ] ) ;
return File ;
2016-03-27 20:29:00 +00:00
} ( _Base3 . default ) ;
2015-07-02 21:49:36 +00:00
2016-03-27 20:29:00 +00:00
exports . default = File ;
2015-07-02 21:49:36 +00:00
module . exports = exports [ 'default' ] ;