我正在尝试为 Twilio 可编程聊天工具编写 C# 包装器。提供的库是为 JS 客户端提供的。我认为使用 ClearScript (V8) 之类的工具可以让我根据需要包装 js。
网站上的示例代码是
const Chat = require('twilio-chat');
// Make a secure request to your backend to retrieve an access token.
// Use an authentication mechanism to prevent token exposure to 3rd parties.
const accessToken = '<your accessToken>';
Chat.Client.create(accessToken)
.then(client => {
// Use Programmable Chat client
});
所以在我初始化之后
using (var engine = new V8ScriptEngine())
{
engine.Execute(@"
const Chat = require('twilio-chat.js');
const token = 'my token';
Chat.Client.create(token).then(client=>{
});
");
}
'require' 行中带有错误 require 的程序错误未定义。我读过 require 只是返回模块导出,所以我替换了 require('...
engine.Execute(@"
const Chat = ('twilio-chat.js').module.exports;
...
但是无法读取未定义的属性“出口”的错误
我从https://media.twiliocdn.com/sdk/js/chat/releases/4.0.0/twilio-chat.js获得了 js 文件
我该如何解决这个问题,或者也许有更好的方法。我感谢任何和所有的见解。
谢谢