def inbound_sms():
    """
    Function that receives an SMS and returns necessary information
    """
    response = MessagingResponse()
    # Get the SMS message from the request
    inbound_message = request.form.get("Body")

    # Parse the response based on new lines or period,
    # Returns a list of arguments
    message = parse_inbound(inbound_message)

    # Convert message arguments to be url ready
    ready_message = convert_spaces(message)

    # Create API call
    # Only for Meme related calls
    if len(ready_message) < 3:
        for i in range(3 - len(ready_message)):
            ready_message.append("")
    meme_url = "/Users/Jennie/Desktop/text_meme/testing/marked_image.png"

    # Responds with the meme with the img 
    msg = Message().body("Here is your {} meme".format(message[0])).media(meme_url)
    response.append(msg)

    return Response(str(response), mimetype="application/xml"), 200
Exemple #2
0
def inbound_sms():
    """
    Function that receives an SMS and returns necessary information
    """
    account_sid = os.environ['account_sid']
    auth_token = os.environ['auth_token']

    client = Client(account_sid, auth_token)
    caller_ids = client.outgoing_caller_ids.list()

    response = MessagingResponse()
    # Get the SMS message from the request
    inbound_message = request.form.get("Body")

    # Gets the incoming SMS phone number
    inbound_number = request.form.get("From")
    number_list = [caller.phone_number for caller in caller_ids]
    if inbound_number not in number_list:
        msg = Message().body(
            "Looks like you havent signed up for TextMeme. You can sign up via this link: http://34.210.213.199/sign_up.html#/"
        )
    else:
        # Parse inbound message
        message = parse_inbound(inbound_message)
        meme = message[0]
        top = message[1]
        bot = message[2]

        # Spelling Error Check for Memes

        # Check for START command
        if "Start" == meme:
            msg = Message().body(
                "Welcome to TextMeme! To make a meme, text me the meme name and the top and bottom text you want, seperated by a period."
            )
        else:
            # Check if meme exists, if not let user know
            if meme not in open('meme_list').read():
                msg = Message().body(
                    "Having trouble? Text START to learn how to use or Check our our available memes here: INSERT"
                ).media("http://m.memegen.com/hxg2qb.jpg")
            else:
                # Responds with the meme with the img
                url = 'http://34.210.213.199:8080/api/v1/get_image/' + meme + ':' + top + ':' + bot
                msg = Message().body("Here is your meme").media(url)

    response.append(msg)
    return Response(str(response), mimetype="application/xml"), 200
Exemple #3
0
def inbound_sms():
    """
    Function that receives an SMS and returns necessary information
    """
    response = MessagingResponse()
    # Get the SMS message from the request
    inbound_message = request.form.get("Body")

    # Parse the response based on new lines or period,
    # Returns a list of arguments
    message = parse_inbound(inbound_message)

    # Opens the image, determine width & height for font resizing
    imgFile = "images" + message[0] + ".jpg"
    img = Image.open(imageFile)
    W, H = img.size

    # Variables for message and font
    msg_top = message[1]
    fontsize = 1
    img_fraction = 0.75

    draw = ImageDraw.Draw(img)

    # Loop to determine fontsize
    font = ImageFont.truetype("/Library/Font/Impact.ttf", fontsize)
    while font.getsize(msg)[0] < img_fraction * img.size[0]:
        fontsize += 1
        font = ImageFont.truetype("/Library/Font/Impact.ttf", fontsize)

    # Draw the new meme with given fontsize
    w, h = draw.textsize(msg, font)
    draw.text(((W - w) / 2, 0), msg, font=font)
    draw = ImageDraw.Draw(img)

    img.save("temporary_image.png")

    # Responds with the meme with the img
    msg = Message().body("Here is your {} meme".format(
        message[0])).media("temporary_image.png")
    response.append(msg)

    return Response(str(response), mimetype="application/xml"), 200
Exemple #4
0
def handle_command(command, channel):
    """
        Receives commands directed at the bot and determines if they
        are valid commands. If so, then acts on the commands. If not,
        returns back what it needs for clarification.
    """
    message = parse_inbound(command)
    ready_message = convert_spaces(message)
    if len(ready_message) < 3:
        for i in range(3 - len(ready_message)):
            ready_message.append("")
    meme_url = "http://apimeme.com/meme?meme={}&top={}&bottom={}".format(
        ready_message[0], ready_message[1], ready_message[2])
    r = requests.get(meme_url)
    if 'No meme found' not in r.text:
        response = meme_url
    else:
        response = "https://img.memesuper.com/abd9230cf6066288b1ddce774a9baeee_do-you-even-meme-do-u-even-meme_400-400.jpeg"
    slack_client.api_call("chat.postMessage",
                          channel=channel,
                          text=response,
                          as_user=True)