Skip to content

Instantly share code, notes, and snippets.

def send_gif_message(recipient_id, message):
gif_url = search_gif(message)
data = json.dumps({
"recipient": {"id": recipient_id},
"message": {
"attachment": {
"type": "image",
"payload": {
"url": gif_url
def search_gif(text):
#get a GIF that is similar to text sent
payload = {'s': text, 'api_key': '<GIPHY_API_KEY>'}
r = requests.get('http://api.giphy.com/v1/gifs/translate', params=payload)
r = r.json()
url = r['data']['images']['original']['url']
return url
def send_text_message(recipient_id, message):
data = json.dumps({
"recipient": {"id": recipient_id},
"message": {"text": message}
})
params = {
"access_token": <PAGE_ACCESS_TOKEN>
}
@app.route('/', methods=['POST'])
def handle_messages():
data = request.get_json()
entry = data['entry'][0]
if entry.get("messaging"):
messaging_event = entry['messaging'][0]
sender_id = messaging_event['sender']['id']
message_text = messaging_event['message']['text']
send_text_message(sender_id, message_text)
return 'ok', 200
@teenoh
teenoh / bot.py
Last active November 1, 2017 22:30
import json
import requests
from flask import Flask, request
VERIFY_TOKEN = "giphy"
app = Flask(__name__)
@app.route('/', methods=['GET'])
def verify():
@teenoh
teenoh / bad-bot-workflow.txt
Created October 13, 2017 14:58
bad-bot-workflow
if user enters "hey" =>
reply user "hi"
if user enters "hello" =>
reply user "hi"
if user enters "hi" =>
reply user "hi"
if user entered "where are you?" =>
@teenoh
teenoh / bot code
Last active October 13, 2017 14:54
Bot workflow
if user entered "hey" =>
reply user with "hi"
if user entered "where are you?" =>
reply user with "I am somewhere in the cloud"
if user entered "what is your name?" =>
reply user with "I am Bot"
`