2017-01-23 54 views
1

我想創建2個用戶之間的一個簡單的聊天應用程序,使用twilio JS API。Twilio聊天客戶渠道名單

的想法是,我知道這兩個用戶將不得不與對方聊天,我想創建一個特定的渠道,他們兩人之間的聊天。 因此,當一個用戶登錄時,我想它的名字搜索通道:

  • ,如果它已經存在,則意味着其他用戶已經登錄了,我想加入這個通道。
  • 別的,我想用這個特定的名字創建一個頻道,然後等待其他用戶。

我試過2個備選方案: 1.聊天客戶端。 2. IPMessaging客戶端。

我想用戶此功能:

chatClient.getChannels().then(function (channels){ // search for the channel I need // } 

但對聊天頻道出現以下錯誤:

twilio TypeError: chatClient.getChannels is not a function 
與IPMESSAGING客戶端這一切運作良好

這樣,但我可以」 t觸發用戶打字事件,這對我的應用很重要:

chatChannel.on('typingStarted', function(){ 
    console.log('user started typing') 
}); 
chatChannel.on('typingEnded', function(){ 
    console.log('user stopped typing') 
}); 

如果這個事件是pos能夠觸發IPMessaging客戶端? 如果不是,我如何獲得聊天客戶端的頻道列表?

謝謝

回答

1

可以觸發與IPMESSAGING(可編程聊天)輸入指標: 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(); 
    } 
}); 

這同一個事件可以觸發成員,不僅渠道。 https://media.twiliocdn.com/sdk/js/chat/releases/0.11.1/docs/Member.html