Twilio Chat - Joining a user to a channel with identity and friendlyName - twilio

How do i create a user and join that user into a channel with a friendly name ?
All the examples in the documentation located here assumes that a user with appropriate friendlyName is already present in the service instance.
So, if i want to join a user in my system to a channel, Do i need to first create a user using users rest api endpoint and then add that user as a member of a channel ?
channel.members.create(user.identity)
Above code above throws 409 conflict error if i re-create a user. So i am forced to fetch a user, see if the user exists then create the user. If user already exists, then I have to update the user with friendlyName.
I am forced to check if the user in my system exists in that service instance everytime that user joins a channel.
Is there a way I can join a user to a channel with friendly name so Twilio creates if the user doesn't exist and update friendly name if user already is in twilio service instance ?
This is the sequence of events I would like to see:
User in my system clicks join room button
Either from client side or server side, I join the user into that channel with identity and friendlyName.
Twilio creates a user/member in service instance and
channel if the user/member doesnt exist Twilio updates a
user/members friendly name if the user already exists.

2022 answer:
const participant = await conversation.getParticipantByIdentity(userIdentity);
if (!participant) {
await conversation.join();
}
And yes, yon need to use Conversation API.

Related

How to get the email from a user / agent from a custom lookup field

We have a custom field with a type lookup in Zendesk connected to a form. Which gives us the possiblity to add another user object to a ticket.
But I am not able to figure out how to get that email address from that field in the ticket.
The documentation describes that if you select a relation you get a agent or user object. By getting this object, you can address the fields for that object.
But this is not working for us.
For example, the field ID 11963774080017
So to address the name in the field, we use {{ticket.ticket_field_11963774080017}}.
But when using the following {{ticket.ticket_field_11963774080017.user.email}}.
I am not able to fetch the user email.
Many thanks.

Organization based restrictions for participant identity issuing in Hyperledger Composer

lets say we have a 2 organization network (OrgA and OrgB) both organizations have there own "Admin" identity that can issue identities. If the admin identity for OrgA issues a identity for a participant "ParA", how can one prohibit OrgB to issue a identity for that participent?
You can use ACLs to restrict the kind of participants created or that are viewable, by either Organisation's admins. Simplest way is designated participant classes for each Org and control access to participants by class
Alternatively, they can be in the same participant class but have identifying Org metadata, ie. where you DO insist that the participants are created in the same participant class. Then (with ACLs in place) the org admin from 'another org' won't have the capability to bind an identity he issued, to the 'wrong' participant (ie one he should not even see, to bind it to), because a condition check in the ACL will prevent the access.
eg
rule myRule1 {
description: "Org admin can see/access/create participants matching own org"
participant(p): "org.acme.nwk.IssuerAdmins" // ie only someone of this class, can 'issue identities' -
operation: ALL // (CREATE, READ, UPDATE, DELETE) // do everything, for IDs in their Org ?
resource(r): "org.acme.nwk.myParticipants"
condition: (p.organisation == r.organisation) // can ONLY see or do anything with participants from own Org
action: ALLOW
}
An Org Admin from a 'different' org - can issue identities, but will not be able to see a participant 'not in his/her Org' (to try map to his own org's identities).
Its possible to be more 'succinct' and base it on data, but putting complex javascript evaluations (check the attribute value for an Org pattern sequence etc) adds more overhead, if large amounts of data is being compared against.
you could also do another way:

How can I get all logged-in users on my website?

I need all active users logged on my website. I know I can take my logged-in user:
var currentUser = manager.FindById(User.Identity.GetUserId());
but how can I take all?
ASP.NET membership has a feature that works for FormsAuthentication. Otherwise you need to write to a persistent store somewhere the most recent activity date & then query that table for all users active within a certain window. A web app is stateless, so "actively logged" in is a fictional abstraction we imagine over a stateless protocol. After a request is over the server has forgotten about you. Another hack might be to count how many sessions are still alive if you are using sql session store.
Create a field in user table named "IsLogin".
Set IsLogin = 0 when user Signup.
Update the field whenever user logged in to the system i.e. IsLogin = 1
Now in order to get all logged-in users :
Check all records in a user table whose have IsLogin = 1
Your choice save the result in user object or just store ids or names of those users who are logged-in
Hence you store the result in array or any collection (i.e List)
Now you can easily enumerate list from start till end to get all logged-in users.
I used this method, It is the most recommended way.

Creating new user with Valence API and setting profile data

I'm successfully creating a new user using the valence API, setting the password and enrolling the new user into appropriate OUs.
(I've used the API reference at: http://docs.valence.desire2learn.com/reference.html)
I'm logged on using an account created for the application accessing the REST API.
I also want to set some of the profile fields for the new user;
I think I need to use the put profile function:
PUT /d2l/api/lp/(D2LVERSION: version)/profile/(D2LID: profileId)
My issue is how to find the profile id for the user i've just created.
It isn't returned in the user data for the created user and I can't see the API call which would let me retrieve the profile id of the newly created user.
Can anyone point me in the right direction?
Cheers
Alan
After creating a user you will have its user ID. If you make the following call (documentation)
GET /d2l/api/lp/(D2LVERSION: version)/enrollments/orgUnits/(D2LID: orgUnitId)/users/
You will get a list of all users enrolled in the provided org unit. Note that the result set of this call is paged (see the docs.) Each entry in the result is a Enrollment.OrgUnitUser, which contains a property "user" with a User.User value - which contains the users profile identifier.
You can skip ahead to the user you want by setting the bookmark value to the users userID. See the note in the green box in the documentation for the call for more information.
You can always use the root org for the orgUnitID parameter.

API for Changing a User Role in Desire2Learn

In the user api docs it is mentioned that to change the user's role at the organization level we need to use the schema "PUT /d2l/api/lp/(D2LVERSION: version)/users/(D2LID: userId)"
This requires UpdateUserData JSON block as input, but the UpdateUserData JSON block does not have a role id in it. How, then, will we pass the new role of the user?
Role applies to a particular level in the organization so is not an intrinsic property of a user but rather property of the relationship between a user and the org or user and the org unit (department, course etc).
So you could delete and then create the user’s enrollment at the org level . (Id for the org level is retrieved with org info call )
The operation to delete the enrollment is on the enrollment page. And the operation to create the enrollment is on the same page.
However, it is NOT typical for a user to have no enrollment at the org level (e.g. if there was a connection interrupt between delete and create it is not clear what that state of not being enrolled in the org would mean)
I am not sure this fits your application, but, more typical than adding and removing enrollments at the org level is to add and remove them in a particular org level. That way the user always has a presence in the org, but, you can govern permissions via that org unit.

Resources