We need to get sticker file_id and send back to user using sendSticker method

class WebhookHandler(webapp2.RequestHandler):
    def post(self):

        def defaultReply(message=None):
            global reply_method
            reply_method = 'sendMessage'
            message_id = message['message_id']
            chat_id = message['chat']['id']
            msg = 'I understand only text and sticker messages'
            return urllib.urlencode({
                'chat_id': str(chat_id),
                'text': msg.encode('utf-8'),
                'reply_to_message_id': str(message_id),
            })

        def generateTextReply(message=None):
            global reply_method
            reply_method = 'sendMessage'
            message_id = message['message_id']
            chat_id = message['chat']['id']
            first_name = message['from']['first_name']
            text = message['text']
            if text == 'hello':
                msg = 'Xin chao'
            else:
                msg = 'Yo '+first_name+' I got your message'
            return urllib.urlencode({
                'chat_id': str(chat_id),
                'text': msg.encode('utf-8'),
                'reply_to_message_id': str(message_id),
            })

        def generateStickerReply(message=None):
            global reply_method
            reply_method = 'sendSticker'
            chat_id = message['chat']['id']
            sticker = message['sticker']
            file_id = sticker['file_id']
            return urllib.urlencode({
                'chat_id': str(chat_id),
                'sticker': file_id.encode('utf-8'),
            })

        def generateReply(json_body=None):
            if json_body:
                try:
                    message = json_body['message']
                except:
                    message = json_body['edited_message']
                if message:
                    if 'sticker' in message:
                        return generateStickerReply(message)
                    elif 'text' in message:
                        return generateTextReply(message)
                    else:
                        return defaultReply(message)
                else:
                    logging.info('fail to generate reply')
                    return None

            else:
                logging.info('no json_body from telegram update')
                return None

        def sendReply(data=None):
            global reply_method
            if data:
                requestUrl = BASE_URL + reply_method
                resp = urllib2.urlopen(requestUrl, data).read()
            else:
                logging.info('fail to reply')
                resp = None
            logging.info('sendReply response:')
            logging.info(resp)

    reply_method = 'sendMessage'
    urlfetch.set_default_fetch_deadline(60)
    body = json.loads(self.request.body)
    logging.info('Telegram update body:')
    logging.info(body)
    replyData = generateReply(body)
    sendReply(replyData)

Python Global Variable

We need to use global variable to update reply_method name.

  1. reply text with sendMessage
  2. reply sticker with sendSticker

You can read more info here Global Variable