我正在设置一个使用Twilio和ReactJS(咖啡师订购机器人)的聊天机器人,我无法在浏览器上实时显示我的消息。我创建了一个React应用程序,以便每次发送SMS时都可以显示,然后它也将显示在浏览器中。
我转到Twilio控制台,试图查看是否需要在发生同步的地方修改我的功能。
这是创建的令牌函数。
reflect
我在浏览器上遇到这两个错误
exports.handler = function(context, event, callback) {
const ACCOUNT_SID = context.ACCOUNT_SID;
const SERVICE_SID = context.SYNC_SERVICE_SID;
const API_KEY = context.API_KEY;
const API_SECRET = context.API_SECRET;
const IDENTITY = 'barista';
const AccessToken = Twilio.jwt.AccessToken;
const SyncGrant = AccessToken.SyncGrant;
const syncGrant = new SyncGrant({
serviceSid: SERVICE_SID
});
const accessToken = new AccessToken(ACCOUNT_SID, API_KEY, API_SECRET);
accessToken.addGrant(syncGrant);
accessToken.identity = IDENTITY;
const response = new Twilio.Response();
const headers = {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': 'http://localhost:3000',
'Access-Control-Allow-Methods': 'GET',
'Access-Control-Allow-Headers': 'Content-Type'
};
response.setBody({ token: accessToken.toJwt() });
response.setHeaders(headers);
callback(null, response);
};
Access to fetch at 'https://goldenrod-labradoodle-4220.twil.io/barista-token' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
任何帮助,万分感谢。