コード例 #1
0
def update_flow(flow, key):
    try:
        blipSession = BlipSession(key)
        res = blipSession.process_command(set_working_flow(flow))
        print(f'updated flow with status: {res["status"]}')
        return res
    except Exception as ex:
        print(f'failed to update flow - Exception: {ex}')
コード例 #2
0
def update_configuration(config, key):
    try:
        blipSession = BlipSession(key)
        res = blipSession.process_command(set_working_configuration(config))
        print(f'updated configuration with status: {res["status"]}')
        return res
    except Exception as ex:
        print(f'failed to update configuration - Exception: {ex}')
コード例 #3
0
def request_configuration(key):
    try:
        blipSession = BlipSession(key)
        res_config = blipSession.process_command(get_working_configuration())
        config = res_config['resource']
        print(f'requested configuration with status: {res_config["status"]}')
        return config
    except Exception as ex:
        print(f'failed to request configuration - Exception: {ex}')
コード例 #4
0
def request_flow(key):
    try:
        blipSession = BlipSession(key)
        res_flow = blipSession.process_command(get_working_flow())
        flow = res_flow['resource']
        print(f'requested flow with status: {res_flow["status"]}')
        return flow
    except Exception as ex:
        print(f'failed to request flow - Exception: {ex}')
コード例 #5
0
def get_attendants():
    origin_bot_auth_key = '{{origin_bot_auth_key}}'
    origin_bot_session = BlipSession(origin_bot_auth_key)
    skip = 0
    take = 100
    attendants_response = origin_bot_session.force_command(get_request_body(skip, take))
    attendants = attendants_response['resource']['items']
    while attendants_response['resource']['total'] >= 100:     
        skip = 100
        take += 100
        attendants_response = origin_bot_session.force_command(get_request_body(skip, take))
        attendants += attendants_response['resource']['items']

    return attendants
コード例 #6
0
def set_attendants(attendants):
    destiny_bot_auth_key = '{{destinity_auth_key}}'
    destiny_bot_session = BlipSession(destiny_bot_auth_key)
    for attendant in attendants:
        crb = {
            "to": "*****@*****.**",
            "method": "set",
            "uri": "/attendants",
            "type": "application/vnd.iris.desk.attendant+json",
            "resource": create_attendant_body(attendant)
        }

        set_attendant_response = destiny_bot_session.force_command(crb, 3)
        if set_attendant_response['status'] == 'success':
            print(f'{attendant["fullname"]} adicionado com sucesso')
        else:
            print(f'Erro ao adicionar {attendant["fullname"]}')
コード例 #7
0
def main():

    key = input("Insira a Key do seu BOT: ")
    commands = Commands(key)
    bs = BlipSession(commands.bot_key)
    authorization = ''
    while (authorization.lower() != 'sim' and authorization.lower() != 'não'):
        authorization = input(
            "\nEste script atualizará todos os números de telefone de seus contatos para o formato DDXXXXXXXX. Deseja continuar (sim ou não)? : "
        )
        if (authorization.lower() == 'sim'):
            all_contacts = get_all_contacts(commands, bs)
            contacts_from_whatsapp = get_contacts_from_whatsapp(all_contacts)
            invalid_contacts = contacts_invalid_format(contacts_from_whatsapp)
            if (invalid_contacts):
                update_contact(invalid_contacts, bs, commands)
            else:
                print("\nNenhum contato está no formato inválido")
        elif (authorization.lower() == 'não'):
            sys.exit()
コード例 #8
0
        'method': GET_METHOD,
        'to': '*****@*****.**',
        'uri': f'/contexts/{USER_IDENTITY}'
    }


def get_specific_data_context_request(context_var):
    return {
        'method': GET_METHOD,
        'to': '*****@*****.**',
        'uri': f'/contexts/{USER_IDENTITY}/{context_var}'
    }


if __name__ == "__main__":
    blipSession = BlipSession(BOT_AUTHORIZATION)
    res_context = blipSession.process_command(get_all_context_request())
    jsonResponse = {}

    if (res_context.get('status') == 'success'):
        for context_var in res_context['resource']['items']:
            res__get_data_context = blipSession.process_command(
                get_specific_data_context_request(context_var))
            if res__get_data_context['status'] == 'success':
                data_var = res__get_data_context['resource'].encode(
                    'utf-8').decode('utf-8')
                jsonResponse[context_var] = data_var

        print(json.dumps(jsonResponse, ensure_ascii=False))
        print('Finished')
        exit(-1)
コード例 #9
0
from blip_session import BlipSession

my_auth_key = '{{bot_auth_key}}'
bs = BlipSession(my_auth_key)
user_id = '{{phone_number}}@wa.gw.msging.net'
ccrb = {'method': 'get', 'uri': f'/contexts/{user_id}'}

response = bs.force_command(ccrb)
print(response)
context_variables = response['resource']['items']

for context in context_variables:

    bs.process_command({
        'method': 'delete',
        'uri': f'/contexts/{user_id}/{context}'
    })
コード例 #10
0
        'type': 'application/vnd.lime.collection+json',
        'resource': {
            'itemType': 'application/vnd.iris.portal.user-permission+json',
            'items': permissions
        },
        'metadata': {
            'server.shouldStore': 'true'
        }
    }


if __name__ == '__main__':
    print(f'Found {len(BOTS)} bots')
    for bot in BOTS:

        session = BlipSession(bot)
        bot_account = session.force_command(create_get_bot_account())
        bot_account = bot_account['resource']
        bot_identity = bot_account['identity']
        bot_name = bot_account['fullName']

        print(f'Starting to add on {bot_name}...')

        for member in TEAM_MEMBERS:
            print(f'Adding member {member} to {bot_name}')

            commands_to_exec = [
                create_set_auth_permissions(member, ADMIN_AUTH_PERMISSIONS,
                                            bot_identity, bot_name),
                create_set_user(member, bot_identity),
                create_set_user_permissions(member, ADMIN_USER_PERMISSIONS,
コード例 #11
0
from blip_session import BlipSession
import sys

if (len(sys.argv) < 5):
    print(
        'Uso: python import_reports.py <chave_bot_origem> <chave_bot_destino>')
    exit()

first_bot_key = sys.argv[1] + ' ' + sys.argv[2]
second_bot_key = sys.argv[3] + ' ' + sys.argv[4]

first_bot_bs = BlipSession(first_bot_key)
second_bot_bs = BlipSession(second_bot_key)

get_intent_body = {
    "to": "*****@*****.**",
    "method": "get",
    "uri": "/content"
}

bot_intentions = first_bot_bs.force_command(get_intent_body)

print(bot_intentions['resource'])
for intetion in bot_intentions['resource']['items']:
    print(intetion)
    response = second_bot_bs.force_command({
        "to": "*****@*****.**",
        "method": "set",
        "uri": "/content",
        "type": "application/vnd.iris.ai.content-result+json",
        "resource": intetion
コード例 #12
0
    # print(reports)
    return reports['resource']['items']


def create_reports(bot_session, report):
    get_reports_body = {
        "to": "*****@*****.**",
        "method": "set",
        "uri": "/reports/",
        "type": "application/vnd.iris.report+json",
        "resource": report
    }
    response = bot_session.force_command(get_reports_body)
    print(response)


if (len(sys.argv) < 5):
    print(
        'Uso: python import_reports.py <chave_bot_origem> <chave_bot_destino>')
    exit()

origin_bot_key = sys.argv[1] + ' ' + sys.argv[2]
destiny_bot_key = sys.argv[3] + ' ' + sys.argv[4]

origin_bot_session = BlipSession(origin_bot_key)
destiny_bot_session = BlipSession(destiny_bot_key)

destiny_bot_session.process_command
reports = get_reports(origin_bot_session)
for report in reports:
    create_reports(destiny_bot_session, report)
コード例 #13
0
        }
        response = blip_session.force_command(set_flow_rb)
        return response['status']
    except:
        print(new_flow['description'])


if len(sys.argv) < 4:
    print('uso: python deploy_flow.py <arquivo>')
    exit(-1)

bots_file = open(sys.argv[1], 'r', encoding='utf8')
bot_list = json.load(bots_file)
origin_flow = sys.argv[2]
destiny_flow = sys.argv[3]
bots_file.close()

for bot in bot_list:
    origin_session = BlipSession(bot[origin_flow])
    destiny_session = BlipSession(bot[destiny_flow])
    new_flow = get_flow(origin_session)
    current_flow = set_flow(destiny_session, new_flow)
    if current_flow == 'success':
        print(
            f"Fluxo {bot['Id']}-{origin_flow} carregado em {bot['Id']}-{destiny_flow}"
        )
    else:
        print(
            f"Falha ao carregar {bot['Id']}-{origin_flow} em {bot['Id']}-{destiny_flow}"
        )
コード例 #14
0
        'method': GET_METHOD,
        'to': '*****@*****.**',
        'uri': f'/contexts/{USER_IDENTITY}'
    }


def delete_specific_context_variable(context_var):
    return {
        'method': DELETE_METHOD,
        'to': '*****@*****.**',
        'uri': f'/contexts/{USER_IDENTITY}/{context_var}'
    }


if __name__ == "__main__":
    blipSession = BlipSession(BOT_AUTHORIZATION)
    res_context = blipSession.process_command(create_all_context_request())

    if (res_context.get('status') == 'success'):

        for context_var in res_context['resource']['items']:
            res__delete_context = blipSession.process_command(
                delete_specific_context_variable(context_var))
            if res__delete_context['status'] == 'success':
                print(f'Deleted context var :{context_var}')
            else:
                print(
                    f'[ERROR] Reason: {res__delete_context["reason"]["description"]}'
                )

        print('Finished')
コード例 #15
0
from blip_session import BlipSession

bot_auth_key = 'source key'
router_auth_key = 'destination key'

bot_client = BlipSession(bot_auth_key)
router_client = BlipSession(router_auth_key)


def merge_contact(contact, client):
    contact['identity'] = contact['identity'].replace('prd', '')
    client.force_command({
        'method': 'merge',
        'uri': '/contacts',
        'type': 'application/vnd.lime.contact+json',
        'resource': contact
    })


def get_context_values(identity, client):
    command = client.force_command({
        'method': 'get',
        'uri': f'/contexts/{identity}?withContextValues=true&$take=99999'
    })
    command = command['resource']['items']
    command.append({
        'name': 'master-state',
        'type': 'text/plain',
        'value': '*****@*****.**'
    })
    return command