在Microsoft Bot Framework中发送Twilio SMS

问题描述:

我很难让我的机器人发送Twilio消息。我不断收到400个不好的请求我正在将msg对象看作JSON ---我认为我为Twilio创建地址的方式有问题吗?我也已经通过并设置管理工具中的Twilio频道在Microsoft Bot Framework中发送Twilio SMS

SMS == {“data”:{“type”:“message”,“agent”:“botbuilder”,“text”:“test msg“,”address“:{”channelId“:”sms“,”conversation“:{”id“:”4i4hlandl06ha5g3“,”isGroup“:false},”serviceUrl“:”https://sms.botframework.com“,”useAuth“ ,“source”:“sms”}} sendMsg - Session.sendBatch()发送0条消息

所以详细一点。我使用Node.js的,没有错误在控制台您在上面看到是什么sms从JSON版本:

 bot.dialog('sendMsg', function(session, context) { 
     var address = addresses.twilioAddress(session); 
     console.log(JSON.stringify(address)); 
     var sms = new builder.Message().text('test msg').address(address); 
     console.log("SMS == " + JSON.stringify(sms)); 
     bot.send(sms); 
    }).triggerAction({ matches: 'Communication.SendMessage' }) 
} 

我现在的想法是,我创建了地址Twilio错误。下面是一个样子:

module.exports = { 
twilioAddress: function(session) { 
    console.log('made it to twilio Address'); 
    var address = init("twilio test", session, false, 'https://sms.botframework.com', 'sms'); 
    return address; 
} 

}

function init(name, session, isGroup, serviceUrl, channelId) { var address = { channelId: channelId, conversation: { id: session.message.address.id, isGroup: !!isGroup }, serviceUrl: serviceUrl, useAuth: true }; console.log(JSON.stringify(address)); return address; }

同样,我的直觉告诉我,我莫名其妙地压延创建地址。

使用session.send("Message content here");而不是bot.send()

当你使用session.send()它会处理所有的地址的东西给你。

欲了解更多信息,请参阅: https://docs.microsoft.com/en-us/bot-framework/nodejs/bot-builder-nodejs-use-default-message-handler