<commit_before>from flask import Flask
from flask import request

import sys
import os
sys.path.append("..")

from fbmsgbot.bot import Bot
from fbmsgbot.models.message import Message
from fbmsgbot.models.template import Template
from fbmsgbot.models.attachment import WebUrlButton, Element

import json

app = Flask(__name__)
bot = Bot(os.environ['PYBOT_TOKEN'])

@app.route('/', methods=['GET', 'POST'])
def webhook():
    if request.args.get("hub.verify_token") == 'test_token':
        return request.args.get("hub.challenge")

    msgs = bot.messages_for_request(request)
    for m in msgs:

    	msg = None

    	if m.text == 'button':
    		buttons = []
    		b = WebUrlButton('google', 'https://www.google.ca')
    		buttons.append(b)
    		elements = [Element('test', 'http://www.newton.ac.uk/files/covers/968361.jpg', 'test subtitle', buttons)]
    		tmpl = Template('generic', elements=elements)

    		payload = tmpl
    		msg = Message(m.sender, 'template', payload)
    	else:
    		payload = m.text
    		msg = Message(m.sender, 'text', payload)

    	response, error = bot.send_message(msg)
    	print response

    	if error:
    		return 'Bad Request'

    return 'OK'

if __name__ == "__main__":
    app.run(port=8000)<commit_msg>Block messages without text<commit_after>from flask import Flask
from flask import request

import sys
import os
sys.path.append("..")

from fbmsgbot.bot import Bot
from fbmsgbot.models.message import Message
from fbmsgbot.models.template import Template
from fbmsgbot.models.attachment import WebUrlButton, Element

import json

app = Flask(__name__)
bot = Bot(os.environ['PYBOT_TOKEN'])

@app.route('/', methods=['GET', 'POST'])
def webhook():
    if request.args.get("hub.verify_token") == 'test_token':
        return request.args.get("hub.challenge")

    msgs = bot.messages_for_request(request)
    for m in msgs:

    	msg = None

    	if not hasattr(m, 'text'):
    		break

    	if m.text == 'button':
    		buttons = []
    		b = WebUrlButton('google', 'https://www.google.ca')
    		buttons.append(b)
    		elements = [Element('test', 'http://www.newton.ac.uk/files/covers/968361.jpg', 'test subtitle', buttons)]
    		tmpl = Template('generic', elements=elements)

    		payload = tmpl
    		msg = Message(m.sender, 'template', payload)
    	else:
    		payload = m.text
    		msg = Message(m.sender, 'text', payload)

    	response, error = bot.send_message(msg)

    	if error:
    		return 'Bad Request'

    return 'OK'

if __name__ == "__main__":
    app.run(port=8000)
{'fraction_non_alphanumeric': 0.13570019723865878, 'fraction_numerical': 0.007889546351084813, 'mean_word_length': 3.298305084745763, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3172815', 'n_tokens_mistral': 892, 'n_tokens_neox': 851, 'n_words': 205}