gpt4 book ai didi

javascript - Twilio 聊天输入()不起作用

转载 作者:行者123 更新时间:2023-12-03 04:01:40 24 4
gpt4 key购买 nike

我成功地将 twilio 聊天 api 集成到 javascript 上,但是我在 .typing() 函数上遇到了问题,似乎打字功能没有触发

“typingStarted”和“typingEnded”,我可以提供一些建议吗?

这是我的代码

  var chatChannel;
var chatClient;
var username;

$.post("/tokens", function(data) {
username = data.username;
chatClient = new Twilio.Chat.Client(data.token);
chatClient.getSubscribedChannels().then(createOrJoinGeneralChannel);
});

function createOrJoinGeneralChannel() {
// Get the general chat channel, which is where all the messages are
// sent in this simple application
// print('Attempting to join "general" chat channel...');
var promise = chatClient.getChannelByUniqueName("#{params[:chat_channel]}");
promise.then(function(channel) {
chatChannel = channel;
console.log("#{params[:chat_channel]} is exist");
console.log(chatChannel);
setupChannel();
}).catch(function() {
// If it doesn't exist, let's create it
console.log("creating #{params[:chat_channel]} channel");
chatClient.createChannel({
uniqueName: "#{params[:chat_channel]}",
friendlyName: 'General Chat Channel'
}).then(function(channel) {
console.log("Created #{params[:chat_channel]} channel:");
console.log(channel);
chatChannel = channel;
setupChannel();
});
});
}

function setupChannel() {
chatChannel.join().then(function(channel) {
printMessage(username + ' joined the chat.');
chatChannel.on('typingStarted', showTypingStarted);
chatChannel.on('typingEnded', hideTypingStarted);
});
chatChannel.on('messageAdded', function(message) {
printMessage(message.author + ": " + message.body);
});
}

function showTypingStarted(member) {
console.log('somebody is typing');
$('#is_typing').html(member.identity + ' is typing...')
}

function hideTypingStarted(member) {
$('#is_typing').html('');
}

var $input = $('#chat-input');
$input.on('keydown', function(e) {
if (e.keyCode == 13) {
chatChannel.sendMessage($input.val());
$input.val('');
} else {
//console.log('typing');
chatChannel.typing();
}
});

我正在使用此版本的 api

https://media.twiliocdn.com/sdk/js/chat/v1.0/twilio-chat.js

最佳答案

我的错,代码没问题,但是我尝试了错误的用例,我们需要从聊天用户的另一端测试它,而不是在我们自己的聊天窗口上测试它

干杯

关于javascript - Twilio 聊天输入()不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44696478/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com