Why imported Twilio in vuejs is invalid? - vuejs2

I want to use twilio API to my vuejs2 app looking at demo https://github.com/TwilioDevEd/sdk-starter-node:
I added in in project with command
yarn add twilio
But I failed to create Twilio.Chat.Client with valid token, which I got from backendpoint,
as imported twilio object is invalid. In src/main.js I added line :
export const Twilio = require('twilio')
and in my vue page with code:
console.log('initializeChatClient token::')
console.log(token)
console.log('initializeChatClient id::')
console.log(id)
console.log('initializeChatClient channel::')
console.log(channel)
// const Twilio = require('twilio')
console.log('$twilio::')
console.log(Twilio)
console.log('$twilio.Chat::')
console.log(Twilio.Chat)
const client = await Twilio.Chat.Client.create(token)
I got error :
TypeError: Cannot read property 'Client' of undefined
and in console I see invalid twilio object : https://prnt.sc/w41cc7
What is wrong ?
package.json :
"axios": "^0.19.0",
"core-js": "^3.3.2",
...
"twilio": "^3.54.0",
"vue": "^2.6.10",
...
Thanks!

Based on your screenshot, Twilio actually contains a function.
Check out this file: https://github.com/TwilioDevEd/sdk-starter-node/blob/master/src/notification_handler.js:
There is this method that initialises the client using new Twilio(...):
function getTwilioClient() {
// Twilio Library
const client = new Twilio(
config.TWILIO_API_KEY,
config.TWILIO_API_SECRET,
{accountSid: config.TWILIO_ACCOUNT_SID}
);
...
}
Follow the same approach to initialise yours.

Related

Expo React Native - Facebook login is failing in Android device after recent Facebook update

Lately, FB has deprecated the support for Login authentication on Android embedded browsers.
https://developers.facebook.com/blog/post/2021/06/28/deprecating-support-fb-login-authentication-android-embedded-browsers/
Since then I am getting the following error
For your account safety, logging into Facebook from an embedded browser is disabled.
From my code, I tried removing "behavior:web" but it's giving the same error. Is anyone facing the same error in Expo react native?
My Code:
const {
type,
token,
expirationDate,
permissions,
declinedPermissions,
} = await Facebook.logInWithReadPermissionsAsync({
permissions: ['public_profile', 'email']
});
if (type === 'success') {
const response = await fetch(`https://graph.facebook.com/me?fields=id,name,email&&access_token=${token}`);
}
Version Details:
SDK Version: 42.0.0
expo-facebook: ~11.3.1
"react": "16.13.1",
"react-dom": "16.13.1",
"react-native": "0.63.4"
Any help is appreciated.Thanks in advance.

expo-permissions returning Unrecognized Permissions for all persmissions

I am currently working on an app. I was working with react-native and expo versions 34. I've recently faced a big error with sending images to the server, and I tried updating these libraries to version 36.0.0, but since then, expo-permissions only returns errors in every use on iOS, the same error, in fact, written as:
Possible Unhandled Promise Rejection
Error: Unrecognized Permissions: {
notifications
}
I am using the following piece of code:
const { status: existingStatus } = await Permissions.getAsync(
Permissions.NOTIFICATIONS
);
The same error is occurring with the permission for getting the camera roll
I have tried updating the components involved in it until I got these versions of the components:
"react-native": "https://github.com/expo/react-native/archive/sdk-36.0.0.tar.gz",
"expo": "^36.0.0",
"expo-image-picker": "^8.0.1",
"expo-module-scripts": "^1.1.1",
"expo-permissions": "~8.0.0",
"react-native-unimodules": "^0.7.0",
This is my situation. I've tried using both Permissions.askAsync and Persmissions.getAsync, and cleaned the cache and re-installed all the components, as per acording this issue in this github issue: https://github.com/expo/expo/issues/6533
Does anyone has any idea about this?
So, I've figured out one thing which is how to get the CameraRoll permission, but I'm still looking into the Notifications permission.
Instead of using Permission.askAsync(Permissions.CAMERA_ROLL), using this expo-image-picker method will give you the permission:
ImagePicker.getCameraRollPermissionsAsync()
This will properly ask for the permission to access the camera roll in expo 36.
expo-permission is deprecated now. You can request permission from the library you are using.
In your query, you are requesting notification permission, so for that, you can install expo-notifications and request from that.
const { status: existingStatus } = await Notifications.getPermissionsAsync();
let finalStatus = existingStatus;
if (existingStatus !== 'granted') {
const { status } = await Notifications.requestPermissionsAsync();
finalStatus = status;
}
if (finalStatus !== 'granted') {
alert('Failed to get push token for push notification!');
return;
}
I shared the process for requesting permission for the notification. If you have any query feel free to ask.
This is deprecated:
ImagePicker.getCameraRollPermissionsAsync()
You should use:
ImagePicker.getMediaLibraryPermissionsAsync()
You can read a full example and explanation in the following link of how to use your camera and media library:
https://www.kindacode.com/article/image-picker-in-react-native/

react native built-in global objects does not exist at testing usinfg jest

react native built-in global objects like WebSocket does not exist in runnig jest's test
i'm testin my RN app using jest . trying to access RN built-in global WebSocket Object in test files give me undefined. whereas access the object in running app has no problem
app.test.js
console.log(typeof WebSocekt);// return undefined
app.js
console.log(typeof WebSocekt);// return function
expected the WebSocket in jest runner to be function but got undefined as result.
Actually, the WebSocket class doesn't exist globally inside nodejs, but in browsers it does. You can specify the WebSocket you want to use in the constructor like this:
const asteroid = require('asteroid');
const WebSocket = require('ws');
const Connection = asteroid.createClass()
const portal = new Connection({
endpoint: 'ws://localhost:3000/websocket',
SocketConstructor: WebSocket // <-------------- HERE
})

Property 'close' does not exist on type 'Application'

I am importing expressjs like this:
import { Request, Response, Application, Router } from 'express';
const app: Application = require('express')();
and in typings.json:
"express": "registry:npm/express#4.14.0+20160925001530",
when i type app.close() i get:
[ts] Property 'close' does not exist on type 'Application'.
How can i solve this?
Where can i report this? (if it is a bug)
Am i the only one struggling alot with typescript typings?
The definition of Application provided does not have the method close...Server does and (app:Application).listen returns a Server.
start(){
server = app.listen(options.port, function () {
debug('Server listening on port ' + options.port)
})
}
stop(){
server.close();
}
You can report typings that are Definitely typed here. This is the package coming from npm.
Typescript is hard.

How to use Spotify Views API?

How do I use Spotifies Views API the right way?
https://developer.spotify.com/technologies/apps/docs/preview/views/index.html
I am trying to implement a throbber in a div, so I use this code:
require(['$views/throbber#Throbber'], function(Throbber) {
var favs = document.getElementById('favs');
var throbber = Throbber.forElement(favs);
});
But this is throwing an "ReferenceError: require is not defined".
When I use it like this:
var sp = getSpotifyApi();
sp.require(['$views/throbber#Throbber'], function(Throbber) {
var favs = document.getElementById('favs');
var throbber = Throbber.forElement(favs);
});
It is throwing this error." TypeError: Object $views/throbber#Throbber has no method 'match' ".
The Throbber component is only available on 1.X API, using the syntax of your first code snippet.
In order to let the Spotify client know that you are using that version of the API you need to specify in your manifest.json file that are using the 1.X API by adding a Dependencies attribute including the api and views framework:
"Dependencies": {
"api": "1.0.0",
"views": "1.0.0"
}