示例#1
0
def respond():
    if not request.form.get('token'):
        return json("no token")

    channel_id = request.form.get('channel_id')
    text = request.form.get('text')

    connection_data = "host={0} dbname={1} user={2} password={3}".format(
        constants.DB_HOST,
        constants.DB_NAME,
        constants.DB_USER,
        constants.DB_PASS
    )

    print "Connecting to database\n	->%s" % (connection_data)
    connection = psycopg2.connect(connection_data)
    cursor = connection.cursor()
    print "Connected!\n"

    cursor.execute("""
        SELECT
            ipm_channel
        FROM
            visitors
        WHERE
            slack_channel = %s""", (channel_id,))

    ipm_channel = cursor.fetchone()

    if ipm_channel:
        ipm_channel = ipm_channel[0]

        client = TwilioIpMessagingClient(constants.TWILIO_ACCOUNT_SID, constants.TWILIO_AUTH_TOKEN)
        service = client.services.get(constants.TWILIO_SERVICE_SID)
        channel = service.channels.get(sid=ipm_channel)

        response = channel.messages.create(body=text)
    else:
        print('no ipm channel')

    return jsonify(text=text)
示例#2
0
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest.ip_messaging import TwilioIpMessagingClient

# Your Account Sid and Auth Token from twilio.com/user/account
account = "ACCOUNT_SID"
token = "AUTH_TOKEN"
client = TwilioIpMessagingClient(account, token)

# List the users
service = client.services.get(sid="SERVICE_SID")
for u in service.users.list():
    print(u)
示例#3
0
REDCAP_DOCTOR_PROJECT = Project(URL, DOCTOR_TOKEN)
"""

# get credentials for environment variables
TWILIO_ACCOUNT_SID = 'ACbf05fc8a591d9136132c9d62d8319eb1'
TWILIO_AUTH_TOKEN = '09f9ba77cd7c40b602cab2f484e58c07'
TWILIO_API_SECRET = 'R3W2DYt3Eq1hbwj2GRKQV531XeVDU9sJ'

TWILIO_API_KEY = 'SKeed5a60867e8f918ac7f2e9fa819d98a'
TWILIO_IPM_SERVICE_SID = 'IS2ec68050ef5e4c79b15b78c3ded7ddc5'

# old one with testchannel nd general
#TWILIO_SERVICE_SID = 'IS7d421d86df064d9698e91ee6e3d4bcf5'

# Initialize the client
TWILIO_IPM_CLIENT = TwilioIpMessagingClient(TWILIO_ACCOUNT_SID,
                                            TWILIO_AUTH_TOKEN)
TWILIO_IPM_SERVICE = TWILIO_IPM_CLIENT.services.get(sid=TWILIO_IPM_SERVICE_SID)

AZURE_STORAGE_ACCOUNT = CloudStorageAccount(
    "palliassistblobstorage",  # account name
    "r9tHMEj5VV/PwJyjN3KYySUqsnq9tCrxh6kDKFvVY3vrm+GluHN/a1LQjXKYIUzoHEle7x3EyIQwoOijzRJiOA==",  # access key
    "?sv=2016-05-31&ss=b&srt=sco&sp=rwdlac&se=2017-05-25T08:02:01Z&st=2017-04-04T00:02:01Z&spr=https,http&sig=DshFBBFKzV20Ml6sN8D8ZRpbIakU8jlbj8zIBDZP4z8%3D"  # sas token
)
BLOCK_BLOB_SERVICE = AZURE_STORAGE_ACCOUNT.create_block_blob_service()

#print "AZURE_STORAGE_ACCOUNT", AZURE_STORAGE_ACCOUNT
#print "BLOCK_BLOB_SERVICE", BLOCK_BLOB_SERVICE

if sys.version_info < (3, 0):
    reload(sys)
    sys.setdefaultencoding('utf8')