title: Initiate twilio flex chat using node.js
body: <p>I am having difficulty getting twilio flex to show messages created using the API using node.js.</p>
  
  <p>I am creating a channel, adding a member, creating a message on the channel using the member.</p>
  
  <p>The flex dashboard shows the incoming chat request in the task list, I can answer the chat request but none of the messages I save to the channel are show.</p>
  
  <p>The interesting thing is if I use the twilio-flex-webchat.min.js script and initiate a chat from a web page and then get the ChannelSid for that conversation (using <a href="https://chat.twilio.com/v2/Services/ISXXXX/Channels" rel="nofollow noreferrer">https://chat.twilio.com/v2/Services/ISXXXX/Channels</a>) I can use the APIs to create messages for this channel and they appear on the flex dashboard. But I need all this to work via node.js.</p>
  
  <p>I compared the task, channel, reservation, member and message twilio objects both for chat conversations using the twilio-flex-webchat.min.js web library and the objects created by the node.js code. I cannot find any notable difference.</p>
  
  <p>Does anybody have any insights?</p>
  
  <p>Here is my code.</p>
  
  <pre><code>const accountSid = 'ACXXXXXXXXXX';
  const authToken = 'XXXXXXXXXXXXXXXX';
  const workspaceSid = 'WSXXXXXXXXXXXXXXXx';
  const workFlowSid = 'WWXXXXXXXXXXXXXXXXXXXXXX';
  const serviceSid = 'ISXXXXXXXXXXXXXXXXXXXXXX';
  
  
  const client = require('twilio')(accountSid, authToken);
  
  (async () =&gt; {
  
      //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',
          });
  })();
  </code></pre>
  
  <p>Thanks</p>