old_contents: # -*- coding: utf-8 -*-
  import json, urllib
  from flask import Flask, request, abort
  import urlfetch
  
  app = Flask(__name__)
  
  access_token = 'EAAYPCWbw5mYBAIh2WjCZAuYuwOLGu4FsVKnL3XHoULfZB56TPFcMtgnbP7SmRCLZBM38dZAZBiFftOUDzxXfycfgUXav6erFI0n2JFsTvXinSTtgXZBU1hByHyEk4BxmjPw17l089V6YFdoyH9aYAGcdLWVjjcmekVCXBzZBrnOqwZDZD'
  
  
  @app.route("/", methods=["GET"])
  def root():
      return "Hello World!"
  
  
  # webhook for facebook to initialize the bot
  @app.route('/webhook', methods=['GET'])
  def get_webhook():
  
      if not 'hub.verify_token' in request.args or not 'hub.challenge' in request.args:
          abort(400)
  
      return request.args.get('hub.challenge')
  
  
  @app.route('/webhook', methods=['POST'])
  def post_webhook():
      data = request.json
  
      if data["object"] == "page":
          for entry in data['entry']:
              for messaging_event in entry['messaging']:
  
                  if "message" in messaging_event:
  
                      sender_id = messaging_event['sender']['id']
  
                      if 'text' in messaging_event['message']:
                          message_text = messaging_event['message']['text']
                          reply(sender_id, message_text)
  
      return "ok", 200
  
  
  def reply(recipient_id, message_text):
      params = {
          "access_token": access_token
      }
  
      headers = {
          "Content-Type": "application/json"
      }
  
      data = json.dumps({
          "recipient": {
              "id": recipient_id
          },
          "message": {
              "text": message_text
          }
      })
  
      print data
  
      url = "https://graph.facebook.com/v2.6/me/messages?" + urllib.urlencode(params)
      r = urlfetch.fetch(url=url, headers=headers, method='POST', payload=data)
  
new_contents: # -*- coding: utf-8 -*-
  import json, urllib
  from flask import Flask, request, abort
  import urlfetch
  
  app = Flask(__name__)
  
  access_token = 'EAAYPCWbw5mYBADAM4iaXzDVJZBE8qhYutQelEpeibs9Y79ATfsZCqKZB33ZBDy6BgemgMZCJfmWH7cTZC1kiQI67W46bYZBLIfp5ZCd5EtUz6K0Dz6dKaFMnkekDcuyGDAzb8gY2yILs620SIiIt5k0FMycpeLwC85hk66RyYWVHZBwZDZD'
  
  
  @app.route("/", methods=["GET"])
  def root():
      return "Hello World!"
  
  
  # webhook for facebook to initialize the bot
  @app.route('/webhook', methods=['GET'])
  def get_webhook():
  
      if not 'hub.verify_token' in request.args or not 'hub.challenge' in request.args:
          abort(400)
  
      return request.args.get('hub.challenge')
  
  
  @app.route('/webhook', methods=['POST'])
  def post_webhook():
      data = request.json
  
      if data["object"] == "page":
          for entry in data['entry']:
              for messaging_event in entry['messaging']:
  
                  if "message" in messaging_event:
  
                      sender_id = messaging_event['sender']['id']
  
                      if 'text' in messaging_event['message']:
                          message_text = messaging_event['message']['text']
                          reply(sender_id, message_text)
  
      return "ok", 200
  
  
  def reply(recipient_id, message_text):
      params = {
          "access_token": access_token
      }
  
      headers = {
          "Content-Type": "application/json"
      }
  
      data = json.dumps({
          "recipient": {
              "id": recipient_id
          },
          "message": {
              "text": message_text
          }
      })
  
      print data
  
      url = "https://graph.facebook.com/v2.6/me/messages?" + urllib.urlencode(params)
      r = urlfetch.fetch(url=url, headers=headers, method='POST', payload=data)
  
subject: correct access token