import json
import logging
import urllib
import urllib2
from flask import Flask, Response, request
from google.appengine.api import urlfetch, memcache
app = Flask(__name__)
# Note: We don't need to call run() since our application is embedded within
# the App Engine WSGI application server.
TOKEN = "230588661:AAHxRwP4fH473Sva_XQqF8IAvJGfFtqRH_o"
BASE_URL = 'https://api.telegram.org/bot' + TOKEN + '/'
@app.route('/setwh')
def set_webhook():
    """Exists to setup the webhook from the telegram api to the appengine site"""
    urlfetch.set_default_fetch_deadline(60)
    return json.dumps(json.load(urllib2.urlopen(BASE_URL + 'setWebhook', urllib.urlencode({'url': "https://rembot-1343.appspot.com/webhook"}))))
def give_response(chat_id, message_id, msg):
    resp = urllib2.urlopen(BASE_URL + 'sendMessage', urllib.urlencode({
        'chat_id': str(chat_id),
        'text': msg,
        'disable_web_page_preview': 'true',
        'reply_to_message_id': str(message_id),
    })).read()
    return(resp)


@app.route('/webhook', methods=["PUT", "POST"])
def webhook():
    urlfetch.set_default_fetch_deadline(60)
    requestbody = request.get_json()
    logging.info("raw request:")
    logging.info(requestbody)
    message = requestbody['message']
    chat = message['chat']
    chat_id = str(chat['id'])
    message = requestbody['message']
    text = message.get('text')
    message_id = message.get('message_id')
    give_response(chat_id,message_id,str(text))
    response = Response(requestbody, status=200)
    return(response)

    
@app.route('/')
def hello():
    """Return a friendly HTTP greeting."""
    return 'Hello World!'


@app.errorhandler(404)
def page_not_found(e):
    """Return a custom 404 error."""
    return 'Sorry, Nothing at this URL.', 404


@app.errorhandler(500)
def application_error(e):
    """Return a custom 500 error."""
    return 'Sorry, unexpected error: {}'.format(e), 500

@@ -148,866 +148,1009 @@
 che%0A
-app = Flask(__name__)%0A# Note: We don't need to call run() since our application is embedded within%0A# the App Engine WSGI application server.%0ATOKEN = %22230588661:AAHxRwP4fH473Sva_XQqF8IAvJGfFtqRH_o%22%0ABASE_URL = 'https://api.telegram.org/bot' + TOKEN + '/'%0A@app.route('/setwh')%0Adef set_webhook():%0A    %22%22%22Exists to setup the webhook from the telegram api to the appengine site%22%22%22%0A    urlfetch.set_default_fetch_deadline(60)%0A    return json.dumps(json.load(urllib2.urlopen(BASE_URL + 'setWebhook', urllib.urlencode(%7B'url': %22https://rembot-1343.appspot.com/webhook%22%7D))))%0Adef give_response(chat_id, message_id, msg):%0A    resp = urllib2.urlopen(BASE_URL + 'sendMessage', urllib.urlencode(%7B%0A        'chat_id': str(chat_id),%0A        'text': msg,%0A        'disable_web_page_preview': 'true',%0A        'reply_to_message_id': str(message_id),%0A    %7D)).read()%0A    return(resp)
+from google.appengine.ext import ndb%0Aapp = Flask(__name__)%0A%0A#constant for connecting to telegram%0ATOKEN = %22230588661:AAHxRwP4fH473Sva_XQqF8IAvJGfFtqRH_o%22%0ABASE_URL = 'https://api.telegram.org/bot' + TOKEN + '/'%0A%0A%0A#ndd records %0A%0Aclass CronJob(ndb.Model):%0A    time = ndb.DateTimeProperty()%0A    chat_id = ndb.StringProperty()%0A    message_id = ndb.StringProperty()%0A    msg = ndb.StringProperty()%0A%0Adef give_response(chat_id, message_id, msg):%0A    resp = urllib2.urlopen(BASE_URL + 'sendMessage', urllib.urlencode(%7B%0A        'chat_id': str(chat_id),%0A        'text': msg,%0A        'disable_web_page_preview': 'true',%0A        'reply_to_message_id': str(message_id),%0A    %7D)).read()%0A    return(resp)%0A%0A%0A%0A%0A@app.route('/setwh')%0Adef set_webhook():%0A    %22%22%22Exists to setup the webhook from the telegram api to the appengine site%22%22%22%0A    urlfetch.set_default_fetch_deadline(60)%0A    return json.dumps(json.load(urllib2.urlopen(BASE_URL + 'setWebhook', urllib.urlencode(%7B'url': %22https://rembot-1343.appspot.com/webhook%22%7D))))%0A
 %0A%0A%0A@

date time