labpack/messaging/telegram.py
def send_message(self, user_id, message_text, message_style='', button_list=None, small_buttons=True, persist_buttons=False, link_preview=True):

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

        :param user_id: integer with id of telegram user
        :param message_text: string with message to user
        :param message_style: [optional] string with style to apply to text, only 'markdown'
        :param button_list: [optional] list of string to include as buttons in message
        :param small_buttons: [optional] boolean to resize buttons to single line
        :param persist_buttons: [optional] boolean to keep buttons around after exiting
        :param link_preview: [optional] boolean to open up a preview window of a link in message
        :return: dictionary of response details with message details in [json][result]

        {
            'headers': { ... },
            'url': 'https://api.telegram.org/bot.../sendMessage',
            'code': 200,
            'error': '',
            'json': {
                'ok': True,
                'result': {
                    'chat': {
                        'first_name': 'First',
                        'type': 'private',
                        'id': 1234567890,
                        'last_name': 'Last'
                    },
                    'text': 'text me again',
                    'from': {
                        'first_name': 'my Bot',
                        'id': 987654310,
                        'username': 'myBot'
                    },
                    'message_id': 178,
                    'date': 1478729313
                }
            }
        }
        '''

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

    # validate inputs
        input_fields = {
            'user_id': user_id,
            'message_text': message_text,
            'message_style': message_style,
            '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 key word arguments
        request_kwargs = {
            'url': '%s/sendMessage' % self.api_endpoint,
            'data': {
                'chat_id': user_id,
                'text': message_text
            }
        }
        if message_style:
            if message_style == 'markdown':
                request_kwargs['data']['parse_mode'] = 'Markdown'
            elif message_style == 'html':
                request_kwargs['data']['parse_mode'] = 'HTML'
        if button_list:
            request_kwargs['data']['reply_markup'] = self._compile_buttons(button_list, small_buttons, persist_buttons)
        # elif keypad_type:
        #     request_kwargs['data']['reply_markup'] = self._compile_keypad(keypad_type, persist_buttons)
        if not link_preview:
            request_kwargs['data']['disable_web_page_preview'] = True

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

        return response_details
 a method to send a message using telegram api

        :param user_id: integer with id of telegram user
        :param message_text: string with message to user
        :param message_style: [optional] string with style to apply to text, only 'markdown'
        :param button_list: [optional] list of string to include as buttons in message
        :param small_buttons: [optional] boolean to resize buttons to single line
        :param persist_buttons: [optional] boolean to keep buttons around after exiting
        :param link_preview: [optional] boolean to open up a preview window of a link in message
        :return: dictionary of response details with message details in [json][result]

        {
            'headers': { ... },
            'url': 'https://api.telegram.org/bot.../sendMessage',
            'code': 200,
            'error': '',
            'json': {
                'ok': True,
                'result': {
                    'chat': {
                        'first_name': 'First',
                        'type': 'private',
                        'id': 1234567890,
                        'last_name': 'Last'
                    },
                    'text': 'text me again',
                    'from': {
                        'first_name': 'my Bot',
                        'id': 987654310,
                        'username': 'myBot'
                    },
                    'message_id': 178,
                    'date': 1478729313
                }
            }
        }
        
a method to send a message using telegram api
a method to send a message using telegram api
def send_message(self, user_id, message_text, message_style='', button_list=None, small_buttons=True, persist_buttons=False, link_preview=True):
        title = '%s.send_message' % self.__class__.__name__
        input_fields = {
            'user_id': user_id,
            'message_text': message_text,
            'message_style': message_style,
            '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)
        request_kwargs = {
            'url': '%s/sendMessage' % self.api_endpoint,
            'data': {
                'chat_id': user_id,
                'text': message_text
            }
        }
        if message_style:
            if message_style == 'markdown':
                request_kwargs['data']['parse_mode'] = 'Markdown'
            elif message_style == 'html':
                request_kwargs['data']['parse_mode'] = 'HTML'
        if button_list:
            request_kwargs['data']['reply_markup'] = self._compile_buttons(button_list, small_buttons, persist_buttons)
        if not link_preview:
            request_kwargs['data']['disable_web_page_preview'] = True
        response_details = self._post_request(**request_kwargs)
        return response_details
def send_message ( self , user_id , message_text , message_style = '' , button_list = None , small_buttons = True , persist_buttons = False , link_preview = True ) : title = '%s.send_message' % self . __class__ . __name__ input_fields = { 'user_id' : user_id , 'message_text' : message_text , 'message_style' : message_style , '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 ) request_kwargs = { 'url' : '%s/sendMessage' % self . api_endpoint , 'data' : { 'chat_id' : user_id , 'text' : message_text } } if message_style : if message_style == 'markdown' : request_kwargs [ 'data' ] [ 'parse_mode' ] = 'Markdown' elif message_style == 'html' : request_kwargs [ 'data' ] [ 'parse_mode' ] = 'HTML' if button_list : request_kwargs [ 'data' ] [ 'reply_markup' ] = self . _compile_buttons ( button_list , small_buttons , persist_buttons ) if not link_preview : request_kwargs [ 'data' ] [ 'disable_web_page_preview' ] = True response_details = self . _post_request ( ** request_kwargs ) return response_details
a method to send a message using telegram api
a method to send a message using telegram api
''' a method to send a message using telegram api

        :param user_id: integer with id of telegram user
        :param message_text: string with message to user
        :param message_style: [optional] string with style to apply to text, only 'markdown'
        :param button_list: [optional] list of string to include as buttons in message
        :param small_buttons: [optional] boolean to resize buttons to single line
        :param persist_buttons: [optional] boolean to keep buttons around after exiting
        :param link_preview: [optional] boolean to open up a preview window of a link in message
        :return: dictionary of response details with message details in [json][result]

        {
            'headers': { ... },
            'url': 'https://api.telegram.org/bot.../sendMessage',
            'code': 200,
            'error': '',
            'json': {
                'ok': True,
                'result': {
                    'chat': {
                        'first_name': 'First',
                        'type': 'private',
                        'id': 1234567890,
                        'last_name': 'Last'
                    },
                    'text': 'text me again',
                    'from': {
                        'first_name': 'my Bot',
                        'id': 987654310,
                        'username': 'myBot'
                    },
                    'message_id': 178,
                    'date': 1478729313
                }
            }
        }
        ''' # validate inputs
 # construct key word arguments
 # elif keypad_type:
 #     request_kwargs['data']['reply_markup'] = self._compile_keypad(keypad_type, persist_buttons)
 # send request

dictionary of response details with message details in [json][result]
{
'headers': { ...
dictionary of response details with message details in [ json ] [ result ] { ' headers ' : { ...
self
user_id
integer with id of telegram user
integer with id of telegram user
message_text
string with message to user
string with message to user
message_style
[optional] string with style to apply to text, only 'markdown'
[ optional ] string with style to apply to text only ' markdown '
button_list
[optional] list of string to include as buttons in message
[ optional ] list of string to include as buttons in message
small_buttons
[optional] boolean to resize buttons to single line
[ optional ] boolean to resize buttons to single line
persist_buttons
[optional] boolean to keep buttons around after exiting
[ optional ] boolean to keep buttons around after exiting
link_preview
[optional] boolean to open up a preview window of a link in message
[ optional ] boolean to open up a preview window of a link in message