Esempio n. 1
0
def init():
    global page
    TABOT_ACCESS_TOKEN = "EAANbYW2bhcwBAHprKcgSrs86S3MFVdVv37auFZBAo4EPzAMTjKNDQuLj9227ai1Agbryvs2QXcHQgf7vHs2Xv0YynvT7XDo4wPAjSHabFyvbJVQfkUkZCJP7PZBRZBcLctaT7MG0aDSJDFZCBbnxcfR8KB48i9YAWLiIAmSmRevoiIfLGWUIY"
    page = Page(TABOT_ACCESS_TOKEN)
    page.show_starting_button("GET_START")
    page.greeting(
        "Hi {{user_first_name}}! TaBot is Messenger Bot to help you know more about Celcom Prepaid Package. Let's Get Started!"
    )
    page.show_persistent_menu([
        Template.ButtonPostBack("Available command ⚛️", 'COMMAND'),
        Template.ButtonWeb("Celcom website 📱", "https://www.celcom.com.my"),
        Template.ButtonPostBack("tabot", 'START')
    ])
    ## 當使用者按下選單中的'重新查詢'時
    elif payload == 'REFRESH':
        text = '你希望想擁有的信用卡特色?'
        page.send(sender_id, text, quick_replies=[{'title': '高額現金回饋', 'payload': 'cash'},
                                                  {'title': '旅遊交通', 'payload': 'traffic'},
                                                  {'title': '休閒娛樂', 'payload': 'entertain'},
                                                  {'title': '購物', 'payload': 'shopping'},
                                                  {'title': '電子支付功能(悠遊卡、一卡通)', 'payload': 'easycard'},
                                                  {'title': '宗教', 'payload': 'religion'}])
    ## 當使用者按下卡片中的'詳細資訊'時
    else:
        page.send(sender_id, card_detail(payload))

########################################################
## 設置起始按鈕與常駐選單
page.greeting('我們是一群致力於讓各位elite成為卡奴的學生,想變卡奴找我們準沒錯!')
page.show_starting_button('START')
page.show_persistent_menu([Template.ButtonPostBack('重新查詢', 'REFRESH'),
                           Template.ButtonWeb('前往此網頁以獲得更多資訊', 'https://money101.com.tw'),
                           Template.ButtonWeb('讓你看看我們的資料庫!', 'https://github.com/chrisyang-tw/PBC_Final/blob/master/data.csv')])

########################################################
## 訊息傳送與判斷
@page.handle_message
def message_handler(event):
    sender_id = event.sender_id
    message = event.message_text

    ## 讓機器人在使用者傳送訊息後立刻已讀訊息並開啟輸入指示器(點點點符號)
    page.mark_seen(sender_id)
    page.typing_on(sender_id)
Esempio n. 3
0
        text = 'Hi ' + user_profile[
            'first_name'] + ' 歡迎來到 龜 婦 の 生 活 😊\n您今天來到這裡有什麼能替您服務的嗎?'
        page.send(sender_id,
                  text,
                  quick_replies=[{
                      'title': '商品詢問',
                      'payload': 'Y'
                  }, {
                      'title': '訂購商品',
                      'payload': 'Y'
                  }])


########################################################
## 設置起始按鈕與常駐選單
page.greeting(
    '☆分享金龜婿と龜婦的台日生活\n★愛購物更ღ日貨的龜婦因此走上代購這條不歸路...\n★日本代購/網站代購(衣服.包包.帽子等)皆可私')
page.show_starting_button('START')
page.show_persistent_menu([Template.ButtonPostBack('重新查詢', 'REFRESH')])

########################################################
## 訊息傳送與判斷


@page.callback(['dealCart'], types=['POSTBACK'])
def callback_picked_genre(payload, event):
    global profile
    sender_id = event.sender_id
    count = 1
    cartSum = 0
    text = ''
    if len(profile[sender_id].orderDetail):
Esempio n. 4
0
from flask import request
from fbmq import Attachment, Template, QuickReply, Page
import time
from .models import *
from .globals import *
from .graph import *

CART_ITEM = Item()

page = Page(ACCESS_TOKEN)
page.greeting("{{user_first_name}}, Welcome to Circuit House!")

# Starting button action
page.show_starting_button("START_PAYLOAD")


# Starting Button Callback Handler
@page.callback(['START_PAYLOAD'])
def start_callback(payload, event):
    print("GET STARTED TRIGGERED!")
    sender_id = event.sender_id
    profile = get_user_info(sender_id)
    sender_name = profile['first_name']

    page.typing_on(sender_id)
    time.sleep(.3)
    page.typing_off(sender_id)

    # Conversation Starter
    quick_replies = [
        QuickReply(title="📦 Order Product", payload="PICK_ORDER"),
Esempio n. 5
0
app = Flask(__name__)
app.config[
    "SQLALCHEMY_DATABASE_URI"] = "mysql://*****:*****@localhost/bot_db"
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
app.secret_key = "horhe borhes"
""" EOF """
""" Flask_Migrate instance """
migrate = Migrate(app, db)
""" page instance setup """
page = Page(PAGE_ACCESS_TOKEN)
page.show_starting_button("GET_STARTED")
page.show_persistent_menu([
    Template.ButtonPostBack('contact info', 'PERSISTENT_CONTACT_INFO'),
    Template.ButtonWeb("MOVEONCOMPANY", "www.google.com")
])
page.greeting("Hello!")
""" EOF """
"""for modularity"""
""" EOF """


@app.route('/', methods=['POST'])
def webhook():
    """the center of all """
    data = request.get_json()
    # pprint(data)  #FIXME: remove this line from production
    page.handle_webhook(request.get_data(as_text=True))
    return "ok", 200


@app.route('/', methods=['GET'])
Esempio n. 6
0

@page.callback(['START_PAYLOAD'])
def start_callback(payload, event):
    """
    Getting started button
    """
    uid = event.sender_id
    check_user(uid)

    page.send(uid, "Hello! I will help you raise your voice. ⚽️")
    page.send(
        uid,
        "All I need is your location, your photo and a small description.")
    page.send(uid, "First, I need your location, please send me one. ⛳️")


# @page.handle_postback
# def postback_handler(event):
#     payload = event.postback_payload

# @page.after_send
# def after_send(payload, response):
#     """:type payload: fbmq.Payload"""
#     print("complete")

if __name__ == "__main__":
    page.greeting("Welcome! I'm Coconut Project 🤖. Can I help you anything?")
    page.show_starting_button("START_PAYLOAD")
    app.run(port=3000)
Esempio n. 7
0
#connects the postgesql to python
app = Flask(__name__)
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['SQLALCHEMY_DATABASE_URI'] = os.environ['DATABASE_URL']
db = SQLAlchemy(app)

#this is the reddit developer acc
reddit = praw.Reddit(client_id = '', client_secret = '', user_agent = 'my user agent')

#This needs to be filled with the PAGE ACCESS TOKEN

PAT= ''
page = Page(PAT)

#this is the welcome screen before you get started
page.greeting("Hi! I'm Todd! If you want to laugh or just need someone to make you happy, I'm the right person to talk to!")


#this will show the get started button
page.show_starting_button("START_PAYLOAD")
@page.callback(['START_PAYLOAD'])
def start_callback(payload, event):
    print("Let's start!")

#the different menus that are being shown
page.show_persistent_menu([Template.ButtonPostBack('What do I do?', 'MENU_PAYLOAD/1'),
                           Template.ButtonPostBack('Hotline', 'MENU_PAYLOAD/2'),
                           Template.ButtonWeb('Other Hotlines', 'http://www.pleaselive.org/hotlines/')]
                          )

@page.callback(['MENU_PAYLOAD/(.+)'])
Esempio n. 8
0
from config import config
from fbmq import Page
from log import logger

page = Page(config['FACEBOOK']['PAGE_TOKEN'])
page.greeting("Welcome!")


@page.handle_message
def message_handler(event):
    """:type event: fbmq.Event"""
    sender_id = event.sender_id
    recipient_id = event.recipient_id
    time_of_message = event.timestamp
    message = event.message

    logger.info(
        "Received message for user %s and page %s at %s with message:" %
        (sender_id, recipient_id, time_of_message))
    logger.info(message)
    try:
        page.send(
            sender_id,
            "🙏 ! I was born like yesterday 👶. So still learning how to interact"
            % message)
        return None
    except Exception as e:
        return Exception(
            'could not send message sender_id={} recipient_id={} time_of_message={}'
            .format(sender_id, recipient_id, time_of_message))
Esempio n. 9
0
                            page.send(
                                sender_id,
                                "Hello je suis Wispi ton compagnon de voyage\n je suis la pour te suggérer des activitées :)\n\nTape aide pour plus d'infos"
                            )
                            continue

                        if sender_id not in BANNED_USERNAME:
                            _thread.start_new_thread(
                                handleMessage.handle,
                                (sender_id, message_text, page))
                        else:
                            alog.warning("SENDER ID IN BANNED USERNAME")
    except:
        print("Exception in user code:")
        print("-" * 20)
        traceback.print_exc(file=sys.stdout)
        print("-" * 20)
        page.send(sender_id, "Il y a eu une erreur désolé")

    return "ok", 200


if __name__ == '__main__':
    page.show_starting_button(GET_STARTED)
    # page.hide_greeting()
    page.greeting(
        "Hello je suis wispi ton compagnon de voyage\n je suis la pour te suggérer des activitées :)"
    )
    page.hide_persistent_menu()
    app.run(port=8042, debug=True)