At some point of tine a want to close connection by channel name or kick an user? I can't use self.close as I'm not on that user at that point when I want to kick him.
P.S. group_discard does not close a connection.
You can send an event to websocket.diconnect just like the other consumer methods:
self.channel_layer.send(
<channel_name>,
{
'type': 'websocket.disconnect',
'code': <code>,
}
)
Related
I have a server side app, which display customer info such as name, id, email etc based on currently opened ticket.
My next task is to update the Requester name in Zendesk App ( server side app ) if i made changes in Ticket Requester before submit.
is that possible?
You can add custom events using client.on('event_type', handler). Refer to ZAF Client API for available events depending on the location.
Here is an example:
if (client) {
client.on('ticket.requester.name.changed', function(e) {
document.getElementById('requesterNameElementId').innerText = e;
});
} else {
console.log('ZAF Client only works within Zendesk iFrame');
}
I'm building a Conference Call console app, where my client wants a Start Call button (instead of starting automatically when the moderator enters.) Since there's no API method for starting a conference, I'm thinking the conference will "start" when the first member enters, but then they'll immediately be put on hold. Later, the moderator will press the "Start Conference" button which will un-hold all the participants. I have 2 questions:
Can I add a .then to the dial.conference() that puts that call on hold, or some other way of doing it from that same runtime function? Or do I have to make an api call from my app when I get the callbackstatus that the member has joined?
When I have 175 participants waiting on hold, do I have to send the list of all their CallSids, or is there some way to un-hold all of them?
Thanks...
Can I add a .then to the dial.conference() that puts that call on hold, or some other way of doing it from that same runtime function? Or do I have to make an api call from my app when I get the callbackstatus that the member has joined?
You dial them into the conference via a <Dial> and <Conference> TwiML, see here. You would set the startConferenceOnEnter attribute to false for all of the participants, see here, that puts them "on hold".
When I have 175 participants waiting on hold, do I have to send the list of all their CallSids, or is there some way to un-hold all of them?
You have two options: A) You can have the moderator dial in and set the startConferenceOnEnter attribute to true for them, this would start the conference. B) If you want a button somewhere in your UI you would need to use the Twilio Rest API, specifically the Conference Resource. The status should be in init and you should set it to in-progress. But I'm not sure about that, an alternative would be to get the moderator via the Conference Participant Resource and then set the startConferenceOnEnter attribute to true. You need to experiment a bit.
Here's what I ended up doing. Let's say the Conference is called Capistrano. I put all the participants into Capistrano with startConferenceOnEnter = false. They're happy.
Then, when a moderator calls in, I recognize them by their phone numbers and I put them into a different conference, Capistrano-backstage. They can chat with each other, etc.
Then, when they press the Start Call button, I make an API call that <Dial> them from Capisrano-backstage to Capistrano, with startConferenceOnEnter = true.
Effectively, the conference started when they pushed the button, but really, it started because they entered. Thanks to #philnash for the assist on the code:
// start-conference receives the Confname, Language and the CallSids of all facilitators 'backstage'
// then moves them all to the conference, which starts it.
// This is your new function. To start, set the name and path on the left.
exports.handler = function(context, event, callback) {
switch (event.Language) {
case 'es-MX':
connectnow = 'Ahora lo estare conectando con '+ event.Confname ;
break;
default :
connectnow = 'Now starting ' + event.Confname;
break;
}
const client = context.getTwilioClient();
const twiml = new Twilio.twiml.VoiceResponse();
twiml.say(connectnow, {voice: 'Polly.Kendra', language: event.Language});
const dial = twiml.dial();
// conf-backstage settings for facilitators
dial.conference({
statusCallback: context.STATUSCALLBACKURL,
statusCallbackEvent: 'start join speaking mute leave',
startConferenceOnEnter: true,
endConferenceOnExit: false,
muted: false,
},
event.Confname);
function transfer(CallSid) {
return client.calls(CallSid).update({ twiml: twiml });
}
Promise.all(event.callSid.map(transfer))
.then(() => {
return callback(null, "success");
})
.catch((error) => {
return callback(error);
});
};
On Swift, I use
socket.on("test") {data, ack in
print(data)
}
In order to subscribe to a room (socket) on my Sails.js API.
When I broadcast a message from the server, with
sails.sockets.broadcast('test', { text : 'ok' })
the socket.on handler is never called.
However, if I set "log" TRUE to config when connecting my socket.io client from swift, in Socket-IO logs the message arrives.
What's wrong?
Eventually, I found my mistake:
The whole process I did is right:
(The request to join the room is done by the server, with sails.sockets.join)
Wrong thing was using socket.on with the ROOM NAME parameter.
I will explain it better, for others having same problem:
From Swift you should subscribe by making a websocket request to an endpoint on the server that accepts websocket requests (GET, POST, PUT). For example, you can make a POST request, passing in the room name into the body.
socket.emitWithAck("post", [
"room": "testroom",
"url": "/api/v1.0/roomsubscribing"
]).timingOut(after: 0) {data in
print("Server responded with \(data)")
}
On server side, inside the room-subscribing endpoint, you should have the following code:
roomSubscribing: function(req, res) {
if (!req.isSocket) {
return res.badRequest();
}
sails.sockets.join(req, req.params('room'), function(err) {
if (err) {
return res.serverError(err);
}
});
}
When the server want to broadcast some data to subscribers of the "testroom" room, the following code must be used:
sails.sockets.broadcast('testroom', { message: 'testmessage' }
Now on the swift's side you must use:
socket.on("message") { data, ack in
print(data)
}
in order to get the message handler to work. I thought you should use room name, instead you should use the KEY of the KEY/VALUE entry you used in your server when you broadcasted the data (in this case, "message").
I only have a small amount of experience with sockets, but in case nobody else answers...
I think you are missing step one of the three step socket process:
A client sends a message to the server asking to subscribe to a particular room.
The client sets up a socket.on to handle particular events from that room.
The server broadcasts an event in a particular room. All subscribers/clients with a .on for that particular event will react.
I could be wrong, but it sounds from your description like you missed step one. Your client has to send a message with io.socket, something like here, then your server has to use the socket request to have them join the room, something like in the example here.
(the presence of log data without the socket.on firing would seem to confirm that the event was broadcast in the room, but that client was not subscribed)
Good luck!
I am trying to create a simple chat app between 2 users, using twilio js api.
The idea is that I know that two users will have to chat with each other, and I want to create a channel specifically for the chat between them both.
So when a user logs in, I want to search the channel by it's name:
if it exist already, it means that the other user is already logged, and I want to join this channel.
else, I want to create a channel by this specific name, and wait for the other user.
I tried 2 alternatives:
1. chat client.
2. IPMessaging client.
I am trying to user this function:
chatClient.getChannels().then(function (channels){ // search for the channel I need // }
But for chat channel I get the following error:
twilio TypeError: chatClient.getChannels is not a function
So with an IPMessaging client it all works well, but I can't trigger events of user typing, which are important for my app:
chatChannel.on('typingStarted', function(){
console.log('user started typing')
});
chatChannel.on('typingEnded', function(){
console.log('user stopped typing')
});
Should this events be possible to trigger for IPMessaging Client?
If not, how can I get the channels list for a chat client?
Thank you
You can trigger typing indicators with IPMessaging (Programmable chat):
https://www.twilio.com/docs/api/chat/guides/typing-indicator
//intercept the keydown event
inputBox.on('keydown', function(e) {
//if the RETURN/ENTER key is pressed, send the message
if (e.keyCode === 13) {
sendButton.click();
}
//else send the Typing Indicator signal
else {
activeChannel.typing();
}
});
That same event can be triggered for members, and not only channels.
https://media.twiliocdn.com/sdk/js/chat/releases/0.11.1/docs/Member.html
Is it possible to know the state of application invoked in blackberry? For example, if we invoke blackberry email application after sending an email, can we know if the application has closed or still running and also where the email has been sent, the subject, the content, etc.? The code may be something like this:
try {
Message message = new Message();
Address address = new Address("email#yahoo.com", "Email");
Address[] addresses = {address};
message.addRecipients(RecipientType.TO, addresses);
message.setContent("Testing email from MyTabViewDemo application");
message.setSubject("Testing Email");
Invoke.invokeApplication(Invoke.APP_TYPE_MESSAGES, new MessageArguments(message));
log.debug(MyApp.GUID_LOG, "Send email action done!");
} catch (Exception e) {
Dialog.inform(e.toString());
}
and how about retrieving the state of other applications like phone, sms, camera?
Thank you.
You can view the visible applications by calling
ApplicationManager.getApplicationManager().getVisibleApplications();
That returns an array of application descriptors. From a descriptor, you can know the names and ids.
It is possible, however, that the messaging app is always on background and cannot be closed (I'm not 100% sure here)
But you can't know if a message has ben sent or not sending the mail like that.