Beispiel #1
0
def s_messaging_create_invite(request, guides_id):
    user = User.objects.get(id=request.session['_auth_user_id'])
    sendbird = SendBirdParams()
    nickname = user.get_short_name
    chat_create_url = 'https://api.sendbird.com/messaging/create'
    # create needs auth key, name
    create_params = {
        'auth': '06078fd7f09c5d053ae6e5862e419fb0c2daa4ae',
        'name': 'test112'
    }
    create_res = sendbird.params_to_bytes(chat_create_url, create_params)

    try:
        messaging_channel_url = create_res['channel']['channel_url']
    except KeyError:
        print("Error, chat_create")
        return render(request, 'chat/chat.html', {'state': 'error', 'id': str(user.id), 'nickname': nickname})

    # invite needs auth key, channel url, users_id = [string, ...]
    chat_invite_url = 'https://api.sendbird.com/messaging/invite'
    invite_params = {
        'auth': '06078fd7f09c5d053ae6e5862e419fb0c2daa4ae',
        "channel_url": messaging_channel_url,
        # 유저 본인 아이디, 상대방 아이디 유저객체 id
        "user_ids": [str(user.id), str(guides_id)]
    }
    invite_res = sendbird.params_to_bytes(chat_invite_url, invite_params)
    try:
        if invite_res['error']:
            # error
            print("Error: ", invite_res)
            return render(request, 'chat/chat.html')
    except KeyError:
        print("success invite")
        return render(request, 'chat/chat.html')
Beispiel #2
0
def auth_user(request):
    # Get User Info
    sendbird = SendBirdParams()
    user_auth_url = 'https://api.sendbird.com/user/auth'
    auth_param = {
        'auth': '06078fd7f09c5d053ae6e5862e419fb0c2daa4ae',
        'id': "",
        'issue_access_token': False
    }
    auth_res = sendbird.params_to_bytes(user_auth_url, auth_param)
    return None