示例#1
0
def init_smooch():
    jwt = smooch.get_jwt(app.config["SMOOCH_KEY_ID"], app.config['SMOOCH_SECRET'])
    smooch_api_instance = smooch.SmoochV1(jwt=jwt)

    #test if there are any webhooks for this config
    webhooks_available = smooch_api_instance.list_webhooks()

    #check if the endpoint is in the config
    found = False
    for hook in webhooks_available['webhooks']:
        if hook['target']==app.config["SMOOCH_WEBOOK_ENDPOINT"]:
            found=True

    # tell smooch to start sending events to this place
    if not found:
        print "creating webhook: {0}".format(app.config["SMOOCH_WEBOOK_ENDPOINT"])
        create_response = smooch_api_instance.save_webhook(app.config["SMOOCH_WEBOOK_ENDPOINT"], ["message:appUser", "postback"])

        print create_response
示例#2
0
def get_smooch_api():
    smooch_api_instance = getattr(g, '_smooch_api', None)
    if smooch_api_instance is None:

        jwt = smooch.get_jwt(app.config["SMOOCH_KEY_ID"], app.config['SMOOCH_SECRET'])
        smooch_api_instance = g._smooch_api = smooch.SmoochV1(jwt=jwt)

        #test if there are any webhooks for this config
        webhooks_available = smooch_api_instance.list_webhooks()

        #check if the endpoint is in the config
        found = False
        for hook in webhooks_available['webhooks']:
            if hook['target']==app.config["SMOOCH_WEBOOK_ENDPOINT"]:
                found=True

        # tell smooch to start sending events to this place
        if not found:
            smooch_api_instance.save_webhook(app.config["SMOOCH_WEBOOK_ENDPOINT"], ["message:appUser", "postback"])

    return smooch_api_instance