labpack/messaging/telegram.py
def send_photo(self, user_id, photo_id='', photo_path='', photo_url='', caption_text='', button_list=None, small_buttons=True, persist_buttons=False):

        ''' a method to send a photo using telegram api

        :param user_id: integer with id of telegram user
        :param photo_id: [optional] string with id of file stored with telegram api
        :param photo_path: [optional] string with local path to file
        :param photo_url: [optional] string with url of file
        :param caption_text: [optional] string with caption to add to photo
        :return: dictionary of response details with message detail in [json][result]

        {
            'headers': { ... },
            'url': 'https://api.telegram.org/bot.../sendPhoto',
            'code': 200,
            'error': '',
            'json': {
                'ok': True,
                'result': {
                    'chat': {
                        'first_name': 'First',
                        'type': 'private',
                        'id': 1234567890,
                        'last_name': 'Last'
                    },
                    'caption': 'lab logo',
                    'photo': [
                        {
                            'file_id': 'AgADAQ...EC',
                            'width': 51,
                            'file_size': 1238,
                            'height': 90
                        },
                        {
                            'file_id': 'AgADAQ...Ag',
                            'width': 180,
                            'file_size': 13151,
                            'height': 320
                        },
                        {
                            'file_id': 'AgADAQ...VC',
                            'width': 449,
                            'file_size': 51134,
                            'height': 800
                        },
                        {
                            'file_id': 'AgADAQ...AC',
                            'width': 719,
                            'file_size': 82609,
                            'height': 1280
                        }
                    ],
                    'from': {
                        'first_name': 'my Bot',
                        'id': 987654310,
                        'username': 'myBot'
                    },
                    'message_id': 179,
                    'date': 1478729413
                }
            }
        }
        '''

        title = '%s.send_photo' % self.__class__.__name__

    # validate inputs
        input_fields = {
            'user_id': user_id,
            'caption_text': caption_text,
            'photo_id': photo_id,
            'photo_path': photo_path,
            'photo_url': photo_url,
            'button_list': button_list
        }
        for key, value in input_fields.items():
            if value:
                object_title = '%s(%s=%s)' % (title, key, str(value))
                self.fields.validate(value, '.%s' % key, object_title)

    # construct extension map
        extension_map = self.fields.schema['photo_extensions']

    # construct key word arguments
        request_kwargs = {
            'url': '%s/sendPhoto' % self.api_endpoint,
            'data': {
                'chat_id': user_id
            }
        }
        if caption_text:
            request_kwargs['data']['caption'] = caption_text
        if button_list:
            request_kwargs['data']['reply_markup'] = self._compile_buttons(button_list, small_buttons, persist_buttons)

    # add photo to request keywords
        if photo_path:
            import os
            self._validate_type(photo_path, extension_map, title, 'photo_path')
            if not os.path.exists(photo_path):
                raise ValueError('%s is not a valid file path.' % photo_path)
            request_kwargs['files'] = { 'photo': open(photo_path, 'rb') }
        elif photo_id:
            request_kwargs['data']['photo'] = photo_id
        elif photo_url:
            file_extension = self._validate_type(photo_url, extension_map, title, 'photo_url')
            file_buffer = self._get_data(photo_url, 'photo%s' % file_extension, title, 'photo_url')
            request_kwargs['files'] = { 'photo': file_buffer }
        else:
            raise IndexError('%s(...) requires either a photo_path, photo_id or photo_url argument' % title)

    # send request
        response_details = self._post_request(**request_kwargs)

        return response_details
 a method to send a photo using telegram api

        :param user_id: integer with id of telegram user
        :param photo_id: [optional] string with id of file stored with telegram api
        :param photo_path: [optional] string with local path to file
        :param photo_url: [optional] string with url of file
        :param caption_text: [optional] string with caption to add to photo
        :return: dictionary of response details with message detail in [json][result]

        {
            'headers': { ... },
            'url': 'https://api.telegram.org/bot.../sendPhoto',
            'code': 200,
            'error': '',
            'json': {
                'ok': True,
                'result': {
                    'chat': {
                        'first_name': 'First',
                        'type': 'private',
                        'id': 1234567890,
                        'last_name': 'Last'
                    },
                    'caption': 'lab logo',
                    'photo': [
                        {
                            'file_id': 'AgADAQ...EC',
                            'width': 51,
                            'file_size': 1238,
                            'height': 90
                        },
                        {
                            'file_id': 'AgADAQ...Ag',
                            'width': 180,
                            'file_size': 13151,
                            'height': 320
                        },
                        {
                            'file_id': 'AgADAQ...VC',
                            'width': 449,
                            'file_size': 51134,
                            'height': 800
                        },
                        {
                            'file_id': 'AgADAQ...AC',
                            'width': 719,
                            'file_size': 82609,
                            'height': 1280
                        }
                    ],
                    'from': {
                        'first_name': 'my Bot',
                        'id': 987654310,
                        'username': 'myBot'
                    },
                    'message_id': 179,
                    'date': 1478729413
                }
            }
        }
        
a method to send a photo using telegram api
a method to send a photo using telegram api
def send_photo(self, user_id, photo_id='', photo_path='', photo_url='', caption_text='', button_list=None, small_buttons=True, persist_buttons=False):
        title = '%s.send_photo' % self.__class__.__name__
        input_fields = {
            'user_id': user_id,
            'caption_text': caption_text,
            'photo_id': photo_id,
            'photo_path': photo_path,
            'photo_url': photo_url,
            'button_list': button_list
        }
        for key, value in input_fields.items():
            if value:
                object_title = '%s(%s=%s)' % (title, key, str(value))
                self.fields.validate(value, '.%s' % key, object_title)
        extension_map = self.fields.schema['photo_extensions']
        request_kwargs = {
            'url': '%s/sendPhoto' % self.api_endpoint,
            'data': {
                'chat_id': user_id
            }
        }
        if caption_text:
            request_kwargs['data']['caption'] = caption_text
        if button_list:
            request_kwargs['data']['reply_markup'] = self._compile_buttons(button_list, small_buttons, persist_buttons)
        if photo_path:
            import os
            self._validate_type(photo_path, extension_map, title, 'photo_path')
            if not os.path.exists(photo_path):
                raise ValueError('%s is not a valid file path.' % photo_path)
            request_kwargs['files'] = { 'photo': open(photo_path, 'rb') }
        elif photo_id:
            request_kwargs['data']['photo'] = photo_id
        elif photo_url:
            file_extension = self._validate_type(photo_url, extension_map, title, 'photo_url')
            file_buffer = self._get_data(photo_url, 'photo%s' % file_extension, title, 'photo_url')
            request_kwargs['files'] = { 'photo': file_buffer }
        else:
            raise IndexError('%s(...) requires either a photo_path, photo_id or photo_url argument' % title)
        response_details = self._post_request(**request_kwargs)
        return response_details
def send_photo ( self , user_id , photo_id = '' , photo_path = '' , photo_url = '' , caption_text = '' , button_list = None , small_buttons = True , persist_buttons = False ) : title = '%s.send_photo' % self . __class__ . __name__ input_fields = { 'user_id' : user_id , 'caption_text' : caption_text , 'photo_id' : photo_id , 'photo_path' : photo_path , 'photo_url' : photo_url , 'button_list' : button_list } for key , value in input_fields . items ( ) : if value : object_title = '%s(%s=%s)' % ( title , key , str ( value ) ) self . fields . validate ( value , '.%s' % key , object_title ) extension_map = self . fields . schema [ 'photo_extensions' ] request_kwargs = { 'url' : '%s/sendPhoto' % self . api_endpoint , 'data' : { 'chat_id' : user_id } } if caption_text : request_kwargs [ 'data' ] [ 'caption' ] = caption_text if button_list : request_kwargs [ 'data' ] [ 'reply_markup' ] = self . _compile_buttons ( button_list , small_buttons , persist_buttons ) if photo_path : import os self . _validate_type ( photo_path , extension_map , title , 'photo_path' ) if not os . path . exists ( photo_path ) : raise ValueError ( '%s is not a valid file path.' % photo_path ) request_kwargs [ 'files' ] = { 'photo' : open ( photo_path , 'rb' ) } elif photo_id : request_kwargs [ 'data' ] [ 'photo' ] = photo_id elif photo_url : file_extension = self . _validate_type ( photo_url , extension_map , title , 'photo_url' ) file_buffer = self . _get_data ( photo_url , 'photo%s' % file_extension , title , 'photo_url' ) request_kwargs [ 'files' ] = { 'photo' : file_buffer } else : raise IndexError ( '%s(...) requires either a photo_path, photo_id or photo_url argument' % title ) response_details = self . _post_request ( ** request_kwargs ) return response_details
a method to send a photo using telegram api
a method to send a photo using telegram api
''' a method to send a photo using telegram api

        :param user_id: integer with id of telegram user
        :param photo_id: [optional] string with id of file stored with telegram api
        :param photo_path: [optional] string with local path to file
        :param photo_url: [optional] string with url of file
        :param caption_text: [optional] string with caption to add to photo
        :return: dictionary of response details with message detail in [json][result]

        {
            'headers': { ... },
            'url': 'https://api.telegram.org/bot.../sendPhoto',
            'code': 200,
            'error': '',
            'json': {
                'ok': True,
                'result': {
                    'chat': {
                        'first_name': 'First',
                        'type': 'private',
                        'id': 1234567890,
                        'last_name': 'Last'
                    },
                    'caption': 'lab logo',
                    'photo': [
                        {
                            'file_id': 'AgADAQ...EC',
                            'width': 51,
                            'file_size': 1238,
                            'height': 90
                        },
                        {
                            'file_id': 'AgADAQ...Ag',
                            'width': 180,
                            'file_size': 13151,
                            'height': 320
                        },
                        {
                            'file_id': 'AgADAQ...VC',
                            'width': 449,
                            'file_size': 51134,
                            'height': 800
                        },
                        {
                            'file_id': 'AgADAQ...AC',
                            'width': 719,
                            'file_size': 82609,
                            'height': 1280
                        }
                    ],
                    'from': {
                        'first_name': 'my Bot',
                        'id': 987654310,
                        'username': 'myBot'
                    },
                    'message_id': 179,
                    'date': 1478729413
                }
            }
        }
        ''' # validate inputs
 # construct extension map
 # construct key word arguments
 # add photo to request keywords
 # send request

dictionary of response details with message detail in [json][result]
{
'headers': { ...
dictionary of response details with message detail in [ json ] [ result ] { ' headers ' : { ...
self
user_id
integer with id of telegram user
integer with id of telegram user
photo_id
[optional] string with id of file stored with telegram api
[ optional ] string with id of file stored with telegram api
photo_path
[optional] string with local path to file
[ optional ] string with local path to file
photo_url
[optional] string with url of file
[ optional ] string with url of file
caption_text
[optional] string with caption to add to photo
[ optional ] string with caption to add to photo
button_list
small_buttons
persist_buttons