How to receive an event notification, like "channelAdded", when a new public channel is created - twilio

How can I listen for the creation of any new public channel on a chat service? I have seen client.channelAdded but it only works for private channels.
channelAdded
Fired when a Channel becomes visible to the Client. Fired for created
and not joined private channels and for all type of channels Client
has joined or invited to.
My use case is an internal support application where every first-time incoming SMS message from a customer user results in a new chat service channel for that particular customer user being created, and a chat message being added to the channel representing the SMS. The new channel is created via Twilio REST API.
I want to be able to have every agent user made away that there is a newly created channel (i.e. and open ticket), and then be able to join it if they want (thus making the channel public).
I supposed I could create all private channels and just invite all the agent users to the channel, but seems slightly hacky. Feels like there should be a cleaner way to do this.

Twilio developer evangelist here.
Thanks for the extra information you provided about your use case.
To start with, the channelAdded event will only fire under the circumstances that you described and not for every new public channel. Danila suggested using the webhook to trigger an event, but as you say you are already creating the channel yourself, so no need for a webhook.
Perhaps you could use a channel as a notification for your agents. Create a special channel that all logged in agents join. Then, when you create a new channel for a new open ticket, also send a message to the "open tickets" channel. You could use this channel to then simply notify your agents there is a new request, or you could fire off a function to get the latest channels so it is loaded and ready for your agent to join.
If you wanted something a little more lightweight than a chat channel for this, you could consider using a Twilio Sync list for the currently open tickets that you can then sync with your agents.
Let me know if that helps at all.

One of the possibilities to achieve desired is to add a webhook for the channel creation.
It may add member (customer support person) using REST API to the channel or will send a message to them using REST API.

Related

Microsoft graph notification when new channel created in teams

I would like to receive a webhook notification when a new channel is created in a group in microsoft teams.
I already implemented receiving notifications when user is added to a group through teams (using this API - https://learn.microsoft.com/en-us/graph/api/resources/subscription?view=graph-rest-1.0). Unfortunately, it seems like group subscription is not triggered when a new channel is added.
Is there any other subscription I can use? Thank you in advance.
If you have the possibility to add a bot to the Team, then bots can receive this using the bot event mechanisms. Have a look at Handle bot events, and in particular this section. Once your bot has received the notification, you can of course do whatever you need to do.
Subscribing to channel events is not supported today by Microsoft graph. You can upvote the following idea to help prioritize efforts and also be notified whenever progress is made.
https://microsoftgraph.uservoice.com/forums/920506-microsoft-graph-feature-requests/suggestions/37288522-microsoft-teams-create-channel-with-a-webhook

Twilio chat : Can I get a channel's message history without joining the channel?

I'm using Twilio chat SDK for iOS, and I've run into a problem. I can get the list of channels, get an individual channel, and get the message count for that channel successfully. The next thing I want to do is grab the last message from that channel using getLastWithCount. However, that method's completion is never called.
I need to do this without actually joining the channel, because I'm just trying to get the last message to display in a summary screen with many others. I don't want to join, because the other party may be online on the other end, and it would falsely display the user as online (even if briefly)- when it is simply an automated function at work. (They haven't entered the "chat room" yet.)
I've set client synchronization strategy to .all, and even tried synchronizing the specific channel before attempting getLastWithCount.
How would you get the last message in a Twilio chat channel without joining the channel?
Twilio developer evangelist here.
You can do this, but your users need to have a new permission to do so. The documentation on Users' Roles and Permissions is worth reading to learn more.
Default user permissions are:
createChannel
editOwnUserInfo
joinChannel
But you need one more that allows viewing channels and their messages without joining the channel. One that does this is editChannelName (not obvious, sorry about that).
To do this, you'll want to create a new role and give it those 4 permissions in total. You can then either assign that role to your users or set it as the default role for your Chat service. Once your users have this role and permissions they will be able to view the messages.
Let me know if this helps.

`channelAdded` event from `twilio-chat`

I'm currently upgrading my implementation that uses Twilio IPM to use the new GA release twilio-chat after previously using the twilio-ip-messaging package on npm. There are some disparities between the implementations, but this hasn't really been that much of an issue so far. However it seems that there are some event behaviours that have changed and I struggle to understand why.
Prior to twilio-chat, if I had a client A connected in a browser context, any public channel creation (from another client B, or the server side) would trigger the channelAdded event from twilio. This no longer seems to happen. The new channel is visible on any subsequent getPublicChannelDescriptors call, but I do not receive the event.
Is it possible to opt-in to these events? Or in some other way configure that this should be announced to all connected clients?
I can think of a few workarounds, like a named persistent channel where new channel creation is announced, or some other 'push' mechanism for client A to then refresh its channels list, but all feels a bit dirty when there is already a push mechanism in place that used to effect the same behaviour.
Twilio developer evangelist here.
The channelAdded event for public channels was removed in the Programmable Chat SDKs because of a limitations of how many endpoints can subscribe to a single, global public channels object.
You can receive these events by webhook but you would still need a way to notify the client side of your application. Your suggestion of a persistent channel for this is a good workaround. You could even keep this channel hidden from view and send structured data in the message that would allow you to show the new channel in your interface and request more data about it via the SDK.
If a whole chat channel is too much of a hack, you could also try using Twilio Sync to synchronise a list of active channels between users.
I agree that this does seem like a bit of a hack though. It is possible that all channels will cause the channelAdded event again in the future, but I can't promise anything like that right now, so you will need to workaround it.

Can a private channel communication happen between two Pusher Apps

I have two iOS apps, lets call it Agent app and Customer App.
I have a chat feature between these two apps, but the chats need to be recorded on the server.
I have created two Pusher Apps, one for each of the iOS apps. They both subscribe to their respective private-{id}-channel.
Now every time a message is generated from say Agent app (via HTTP request to server), I want server to create a pusher event with Agent's message on Customer's private channel.
Is it possible to achieve the above using Pusher Private channels?
One way you could achieve this is by having both users join the same channel.
Let's say you have two users: user-a and user-b. Both users subscribe to a common private channel private-chat-user-a-user-b.
let myChannel = pusher.subscribe("private-chat-user-a-user-b")
Then triggering client events on the channel
myChannel.trigger(eventName: "client-my-event", data: ["your": "data"])
Client events are a way of sending messages just between clients, without a server relaying them.
Disclosure: I work at pusher.
I wanted to record the chat on server, therefore, instead of making Customer App directly sending message on Agent App channel, I made the Customer App call my server API, which records the message and relies it on channel that Agent App is listening to.

PubNub best practice: How to manage private rooms?

I'm learning pubnub and I read their documentation but I just can't find how to manage a multi room chat box.
By default, a channel can be listened by anyone.
Subscribing to it and publishing on it is easy.
What I want is to have a main public room (so far so good) but anyone should also be able to talk privately to anyone else without the risk of being read by other users.
These dynamic rooms would be tabbed and the user should be able to go from one to another.
Another requirement would be that talking privately to someone doesn't kick you out of the other rooms you subscribed to (you can still be notified that a new message has been posted on another room while chatting)
What would be the best practice to achieve this?
Would I use different channels (created dynamically)?
Would I use one channel and filter the messages according to their status, pseudo-room id or protagonists?
Would I use multiplexing (one socket only)?
I need to know the best way to achieve this as the documentation only describes basic scenarios with a single room and there's nothing about this on the internet.
Thank you.
PS: I know PubNub doesn't recommend more than 2 channels at a time (even though I have a hard time finding the explanation of this).
PPS: I'm using punbub with socket.io
Socket.IO and PubNub Managing Private Rooms for Chat Services
You are asking for a way to create a Multiroom Chat Service, likely similar to IRC clients, where you are able to join and sit in on multiple chat rooms (on freenode.net for example). This is possible and will take some special tasks to get it right on your part.
You will start by opening Two Channels, one for the main chat room and one for your Private "ME" side chats. With this side Private "ME" channel, you will need to create a long and unpredictable session-id style channel name which typically looks like this:
YTQyOGFiNWEtNTZmZC00OGVhLTgxZjktMWE3ZmMyMzc3MTRhCg==
This is like a reference ID for the user. This ID can be used for Private 1-on-1 chats and the other room can be used for Group Chat. You will secure this Group chat using Access Control Management that we call PubNub Access Manager (PAM).
For additional Security Practices, you will need to review our security recommendations guides available here on PubNub Support for Security on our Help Desk and Knowledge Base.
Now that we have the private channels established, secure communication will be possible by sending and receiving chats via your private server (one that can provide authority) to allow messages to be relayed on a per user basis. You can learn how to do this by reading this section of the Sending Events from a Server to a Socket IO Client Documentation on PubNub.
The second channel will be for public chat for all rooms. For the Multi-tab support you will simply use the channel multiplexing feature of Socket IO on PubNub by adding new rooms via io.connect() method. Every time you open a new tab, you will open a new namespace via io.connect() of which you can have unlimited. Note however that you only should connect to no more than 2 PubNub channels at once (which you already noted in your question).
Here is the PubNub Socket IO method to subscribing to multiple feeds and categories:
Socket.IO Documentation
https://github.com/pubnub/pubnub-api/tree/493d7fc97fb683379fc78be3ca7ad9bc97eb4200/socket.io#restricting-yourself-to-a-namespace
Socket.IO Video on Vimeo
http://vimeo.com/34496366
Example Socket.IO Multiplexing Code
https://github.com/pubnub/pubnub-api/tree/493d7fc97fb683379fc78be3ca7ad9bc97eb4200/socket.io/multiplexing
As a quick conclusion, you will use secure methods to establish a private "ME" channel to send/receive messages on a per-users basis. And a public "Chat" channel that pushes all the public chat room data. Multiplexing will be important for the public chat.
The answers above were correct in 2012, but a lot has changed since then. Private chat rooms can be enabled with PubNub Access Manager, which explicitly grants Publish/Subscribe access on specific channels.
The way this works is through access tokens (aka an "Auth Key"). The developer (you) creates an Auth Key (basically any string of characters) and passes it to PubNub Access Manager. You then set the rules for this Auth Key (i.e. which channels the Auth Key can publish and/or subscribe to).
This Auth Key is provided to any device that needs access to the channel, and used when the device subscribes or publishes to the channel.
Basic docs are available here: http://www.pubnub.com/docs/javascript/tutorial/access-manager.html
Grant 60 minute read/write privilege to channel "privateChat" to an auth_key:
pubnub.grant({
channel : 'privateChat',
auth_key : 'abxyz12-auth-key-987tuv',
read : true,
write : true,
ttl : 60
});
To add to the previous answer, I'm not sure if this is just me hacking things but in order to make multi channel connections with the current socket-io library, you need to set io.connected = false; before passing in another channel config object.
For example:
var pubnub_setup = {
channel : 'public_channel',
publish_key : 'demo',
subscribe_key : 'demo'
};
var private_setup = {
channel : 'private_channel',
publish_key : 'demo',
subscribe_key : 'demo'
};
// Make your public socket connections
var publicSocket = io.connect( 'http://pubsub.pubnub.com/pub_socket', pubnub_setup );
var anotherPublicSocket = io.connect( 'http://pubsub.pubnub.com/another_pub_socket', pubnub_setup);
// Set false otherwise you keep getting back the previous created socket which is
// bound to the original channel 'public_channel'
io.connected = false;
var secretSocket = io.connect( 'http://pubsub.pubnub.com/secret_mulitplex_socket_namespace', private_setup );
Now you can keep creating new secret sockets on the private channel.

Resources