Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
@azure/communication-chat
Advanced tools
Azure client library for Azure Communication Chat services
Azure Communication Services for Chat lets developers add chat capabilities to their app. Use this client library to manage chat threads and their users, and send and receive chat messages.
Read more about Azure Communication Services here
npm install @azure/communication-chat
A chat conversation is represented by a thread. Each user in the thread is called a thread member. Thread members can chat with one another privately in a 1:1 chat or huddle up in a 1:N group chat. Users also get near-real time updates for when others are typing and when they have read the messages.
ChatClient
is the primary interface for developers using this client library. It provides asynchronous methods to create and delete a thread.
ChatThreadClient
provides asynchronous methods to do the message and chat thread members operations within the chat thread.
Use resource url and user access token to initialize chat client.
import { ChatClient } from '@azure/communication-chat';
import { AzureCommunicationTokenCredential } from "@azure/communication-common";
// Your unique Azure Communication service endpoint
let endpointUrl = '<ENDPOINT>';
let userAccessToken = '<USER_ACCESS_TOKEN>';
let tokenCredential = new AzureCommunicationTokenCredential(userAccessToken);
let chatClient = new ChatClient(endpointUrl, tokenCredential);
Use the createThread
method to create a chat thread.
createThreadRequest
is used to describe the thread request:
topic
to give a thread topic;members
to list the thread members to be added to the thread;createThreadResult
is the response returned from creating a thread. It contains a chatThread
which is the thread that was created, as well as an errors
property which will contain information about invalid participants if they failed to be added to the thread.
let createThreadRequest =
{
topic: 'Preparation for London conference',
members:
[
{
user: { communicationUserId: '<USER_ID_FOR_JACK>' },
displayName: 'Jack'
},
{
user: { communicationUserId: '<USER_ID_FOR_GEETA>' },
displayName: 'Geeta'
}
]
};
let chatThreadResult = await chatClient.createChatThread(createThreadRequest);
let threadId = chatThreadResult.chatThread.id;
Use sendMessage
method to sends a message to a thread identified by threadId.
sendMessageRequest
is used to describe the message request:
content
to provide the chat message content;sendMessageOptions
is used to describe the operation optional params:
priority
to specify the message priority level, such as 'Normal' or 'High' ;senderDisplayName
to specify the display name of the sender;sendChatMessageResult
is the response returned from sending a message, it contains an ID, which is the unique ID of the message.
let sendMessageRequest =
{
content: 'Hello Geeta! Can you share the deck for the conference?'
};
let sendMessageOptions =
{
priority: 'Normal',
senderDisplayName : 'Jack'
};
let sendChatMessageResult = await chatThreadClient.sendMessage(sendMessageRequest, sendMessageOptions);
let messageId = sendChatMessageResult.id;
With real-time signaling, you can subscribe to listen for new incoming messages and update the current messages in memory accordingly.
// open notifications channel
await chatClient.startRealtimeNotifications();
// subscribe to new notification
chatClient.on("chatMessageReceived", (e) => {
console.log("Notification chatMessageReceived!");
// your code here
});
Alternatively you can retrieve chat messages by polling the listMessages
method at specified intervals.
for await (const chatMessage of chatThreadClient.listMessages()) {
// your code here
}
Once a thread is created, you can then add and remove users from that thread. By adding users, you give them access to be able to send messages to the thread. You will need to start by getting a new access token and identity for that user. The user will need that access token in order to initialize their chat client. More information on tokens here: Authenticate to Azure Communication Services
// Get a new token created for the user. The token response will contain a token and an identity for the user.
let userTokenResponse = await myTokenFunction();
let addMembersRequest =
{
members: [
{
user: { communicationUserId: userTokenResponse.identity },
displayName: '<NAME>',
shareHistoryTime: '<TIME>'
}
]
};
await chatThreadClient.addMembers(addMembersRequest);
Similar to above, you can also remove users from a thread. In order to remove, you will need to track the IDs of the members you have added.
await chatThreadClient.removeMember({ communicationUserId: '<MEMBER_ID>' });
In this quickstart you learned how to:
If you'd like to contribute to this library, please read the contributing guide to learn more about how to build and test the code.
FAQs
Azure client library for Azure Communication Chat services
The npm package @azure/communication-chat receives a total of 13,841 weekly downloads. As such, @azure/communication-chat popularity was classified as popular.
We found that @azure/communication-chat demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.