I am attempting to write a C# wrapper for the Twilio Programmable Chat tool. The library provided is for JS clients. I thought that using a tool like ClearScript (V8) would allow me to wrap the js as needed.
The example code on the site is
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
});
so after I initialize
using (var engine = new V8ScriptEngine())
{
engine.Execute(@"
const Chat = require('twilio-chat.js');
const token = 'my token';
Chat.Client.create(token).then(client=>{
});
");
}
The program errors on the 'require' line with the error require is not defined. I have read that require is simply returning the module exports so I replaced the require('... with
engine.Execute(@"
const Chat = ('twilio-chat.js').module.exports;
...
but that errors with Cannot read property 'exports' of undefined'
I got the js file from https://media.twiliocdn.com/sdk/js/chat/releases/4.0.0/twilio-chat.js
How can I get around this or maybe there is a better way. I appreciate any and all insights.
Thanks