Javascript 如何在Twilio对话中发送消息
如何向node.js中的Twilio对话发送新消息 我从Twilio中找到了这个示例代码,但我不知道如何为我的对话获取Javascript 如何在Twilio对话中发送消息,javascript,node.js,twilio,twilio-api,twilio-conversations,Javascript,Node.js,Twilio,Twilio Api,Twilio Conversations,如何向node.js中的Twilio对话发送新消息 我从Twilio中找到了这个示例代码,但我不知道如何为我的对话获取messagingServiceSid // Download the helper library from https://www.twilio.com/docs/node/install // Your Account Sid and Auth Token from twilio.com/console // and set the environment variable
messagingServiceSid
// Download the helper library from https://www.twilio.com/docs/node/install
// Your Account Sid and Auth Token from twilio.com/console
// and set the environment variables. See http://twil.io/secure
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const client = require('twilio')(accountSid, authToken);
client.messages
.create({
body: 'Revenge of the Sith was clearly the best of the prequel trilogy.',
messagingServiceSid: 'MG9752274e9e519418a7406176694466fa',
to: '+441632960675'
})
.then(message => console.log(message.sid));
两种选择:
1)通过Twilio控制台进行图形化
2)通过Twilio Rest API编程
这一点让你开始。您还需要将电话号码与信息服务相关联,您可以通过。请注意,该API目前处于公测状态。有两个选项:
1)通过Twilio控制台进行图形化
2)通过Twilio Rest API编程
这一点让你开始。您还需要将电话号码与信息服务相关联,您可以通过。请注意,该API目前正在公开测试版中。单独回答以下问题:
首先创建一个对话并记下对话SID(从CH
开始,在这里用console.log(conversation.SID)
输出):
然后(这是您需要启用SMS的Twilio号码和收件人号码的地方)
现在,您可以使用创建对话的所有参与者都将收到的消息。单独回答以下问题:
// Download the helper library from https://www.twilio.com/docs/node/install
// Your Account Sid and Auth Token from twilio.com/console
// and set the environment variables. See http://twil.io/secure
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const client = require('twilio')(accountSid, authToken);
client.messages
.create({
body: 'Revenge of the Sith was clearly the best of the prequel trilogy.',
messagingServiceSid: 'MG9752274e9e519418a7406176694466fa',
to: '+441632960675'
})
.then(message => console.log(message.sid));
首先创建一个对话并记下对话SID(从CH
开始,在这里用console.log(conversation.SID)
输出):
然后(这是您需要启用SMS的Twilio号码和收件人号码的地方)
现在,您可以使用创建对话的所有参与者都将收到的消息。刚才在我回答后看到这一点。。。你想用手术室吗?在你的问题中,你说的是前者,但你的代码显示的是后者。这些是不同的Twilio产品。是否可以使用node.js中的对话API发送消息?我以为上面的例子就是这样。是的,不同的Twilio产品有时会让人困惑!回答您的问题:是的,您可以将对话API与Node.js一起使用。我添加了另一个例子,因为这是一个完全不同的问题。本质上,您1)创建对话2)添加参与者3)创建消息。出于好奇,您有什么理由需要使用Conversations API吗?对话API在多个参与者的渠道中都有其优势。刚才我在回答了这个问题后看到了这一点。。。你想用手术室吗?在你的问题中,你说的是前者,但你的代码显示的是后者。这些是不同的Twilio产品。是否可以使用node.js中的对话API发送消息?我以为上面的例子就是这样。是的,不同的Twilio产品有时会让人困惑!回答您的问题:是的,您可以将对话API与Node.js一起使用。我添加了另一个例子,因为这是一个完全不同的问题。本质上,您1)创建对话2)添加参与者3)创建消息。出于好奇,您有什么理由需要使用Conversations API吗?Conversations API具有跨多个参与者渠道的优势。
// Download the helper library from https://www.twilio.com/docs/node/install
// Your Account Sid and Auth Token from twilio.com/console
// and set the environment variables. See http://twil.io/secure
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const client = require('twilio')(accountSid, authToken);
client.messages
.create({
body: 'Revenge of the Sith was clearly the best of the prequel trilogy.',
messagingServiceSid: 'MG9752274e9e519418a7406176694466fa',
to: '+441632960675'
})
.then(message => console.log(message.sid));