【问题标题】:Initiate twilio flex chat using node.js使用 node.js 发起 twilio flex 聊天
【发布时间】:2019-08-03 14:14:27
【问题描述】:

我很难让 twilio flex 显示使用 node.js 的 API 创建的消息。

我正在创建频道,添加成员,使用该成员在频道上创建消息。

弹性仪表板在任务列表中显示传入的聊天请求,我可以回答聊天请求,但没有显示我保存到频道的消息。

有趣的是,如果我使用 twilio-flex-webchat.min.js 脚本并从网页发起聊天,然后获取该对话的 ChannelSid(使用 https://chat.twilio.com/v2/Services/ISXXXX/Channels),我可以使用 API 创建此频道的消息,它们出现在 flex 仪表板上。但我需要所有这些通过 node.js 工作。

我比较了使用 twilio-flex-webchat.min.js Web 库和由 node.js 代码创建的对象的聊天对话的任务、频道、预订、成员和消息 twilio 对象。我找不到任何显着的区别。

有人有什么见解吗?

这是我的代码。

const accountSid = 'ACXXXXXXXXXX';
const authToken = 'XXXXXXXXXXXXXXXX';
const workspaceSid = 'WSXXXXXXXXXXXXXXXx';
const workFlowSid = 'WWXXXXXXXXXXXXXXXXXXXXXX';
const serviceSid = 'ISXXXXXXXXXXXXXXXXXXXXXX';


const client = require('twilio')(accountSid, authToken);

(async () => {

    //create channel
    let channel = await client.chat.services(serviceSid)
        .channels
        .create({
            attributes: JSON.stringify({
                status: "ACTIVE",
                from: "Some Person",
                channel_type: "web"
            }),
            workflowSid: workFlowSid,
            taskChannel: 'chat',
            friendlyName: 'Flex WebChat',
            type: 'private'
        });

    //create a member in this channel
    let member = await client.chat.services(serviceSid)
        .channels(channel.sid)
        .members
        .create({ identity: 'WEB_CLIENT' });

    //post a message to this channel from the member
    let message = await client.chat.services(serviceSid)
        .channels(channel.sid)
        .messages.create({ body: 'This is a test message', to: channel.sid, from: 'WEB_CLIENT' });

    //create a task for my programable chat channel and associate the channel sid for my current conversation
    let task = await client.taskrouter.workspaces(workspaceSid)
        .tasks
        .create({
            attributes: JSON.stringify({
                channelSid: channel.sid,
                channelType: "web"
            }),
            workflowSid: workFlowSid,
            taskChannel: 'chat',
        });
})();

谢谢

【问题讨论】:

  • 嗨,迈克,你有什么发现吗?

标签: node.js twilio twilio-api twilio-programmable-chat twilio-flex


【解决方案1】:

在添加消息和创建任务之前,您需要创建一个代理会话,将成员添加为参与者,然后更新频道属性:

    {
      "status": "ACTIVE",
      "forwarding": true,
      "twilioNumber": firstParticipant.proxyIdentifier,
      "serviceNumber": someIdentity,
      "from": from,
      "channel_type": "sms",
      "proxySession": session.sid
    }

【讨论】:

  • 大家好,你们解决了吗?我也完成了网络聊天的所有“标准”设置,并尝试通过可编程聊天/iOS sdk 直接启动我的聊天以显示我的灵活性。似乎没有直接的方法可以做到这一点。在本地复制网络聊天小部件的功能绝对是一个好的开始。我会假设很多这样的配置应该在 Twilio 服务器端,带有 web 钩子和任务等?
猜你喜欢
  • 2019-12-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多