The Talk Object
The Talk
object provides utility functions to help use TalkJS.
Talk.ready is a Promise; any function passed to its then
method is called when
the TalkJS script has loaded. Put all TalkJS-related code in blocks like these. You
can call then
from multiple places if you want. For example:
1Talk.ready.then(function() {2 // Use TalkJS after it has fully loaded3})
1Talk.oneOnOneId(me, other): string
Talk.oneOnOneId(me, other)
Use this helper method to predictably compute a Conversation ID based on participants' ids in the given conversation. Use this method if you want to simply create a conversation between two users, not related to a particular product, order or transaction.
The order of the parameters does not matter. For example, Talk.oneOnOneId("a", "b")
yields the same result as Talk.oneOnOneId("b", "a")
.
This method takes the following steps:
- Take two ids of users and put them in an array
- Sort them lexicographically
- JSON encode them
- Hash the result using SHA1, return the first 20 characters
In pseudocode, this is what this function does:
1var sorted = [me.id, other.id].sort()2 var encoded = JSON.encode(sorted)3 var hash = sha1(encoded) // as lowercase hex4 return truncate(hash, 20)
me
: User | stringA TalkJS User or a string containing the user ID.
other
: User | stringAnother TalkJS User or a string containing the user ID.