I'm trying to send SMS using Twilio nodejs (with Typescript) but, for some reason, I cannot access to create method on messages property (as described in the documentation).
const TWILIO_CLIENT = require('twilio');
let twilioClient = new TWILIO_CLIENT(accountSid, authToken);
let result = await twilioClient.messages.create(smsData);
I get a undefined when trying to access create method, and when I log messages endpoint it only shows my the defined accountSid: { accountSid: "..." }
What could it be?
Related
const accountSid = 'ACf36...'
const authToken = '094...'
const client = require('twilio')(accountSid, authToken)
const VoiceResponse = require('twilio').twiml.VoiceResponse;
client = Client()
twiml = VoiceResponse()
twiml.dial('+912345674127')
call = client.calls.create(
from_ = '+14809078750',
to = '+916395545354',
twiml = str(twiml),
)
console.log(call)
I am trying to make a confrence call using this code and dial function of twilio, but this does not seem to work.
One person successfully joins the room, but 2nd person is not getting call to join the conference.
Twilio developer evangelist here.
First up, it looks as though you included your Account SID and Auth Token in your question. Those credentials give full access to your account and posting them publicly means anyone who comes across them can use them to abuse your account. Please do not do this in the future and change your auth token using this process.
Now, the code you've posted isn't far from being correct for connecting two people in a call. The console.log will not log the call object though, as the result of client.calls.create is a Promise that resolves to a call. Also, str is not a JavaScript function.
Try the following:
const twilio = require('twilio');
const client = twilio(accountSid, authToken);
const VoiceResponse = twilio.twiml.VoiceResponse;
const twiml = new VoiceResponse();
twiml.dial('+912345674127');
client.calls.create({
from: '+14809078750',
to: '+916395545354',
twiml: twiml.toString()
})
.then(call => {
console.log(call);
})
.catch(error => {
console.log(error);
});
If you want to create a conference call, where more than 2 people can join, then you have a bit more work to do. In a conference call the conference acts as a room that people join. So when one person connects to the conference you need to generate a new outbound call using the API to connect another person to the conference. There is a tutorial on how to create conference calls with Twilio that I recommend you go through.
I am using firebase cloud function in my firebase group chat app, Setup is already done but problem is when some one send message in any group then all user get notification for that message including non members of group.
I want to send notification to group specific users only, below is my code for firebase cloud function -
const functions = require('firebase-functions');
const admin = require('firebase-admin');
const _ = require('lodash');
admin.initializeApp(functions.config().firebase);
exports.sendNewMessageNotification = functions.database.ref('/{pushId}').onWrite(event => {
const getValuePromise = admin.database()
.ref('messages')
.orderByKey()
.limitToLast(1)
.once('value');
return getValuePromise.then(snapshot => {
const { text, author } = _.values(snapshot.val())[0];
const payload = {
notification: {
title: text,
body: author,
icon: ''
}
};
return admin.messaging()
.sendToTopic('my-groupchat', payload);
});
});
This will be really help full, if anyway some one can suggest on this.
As per our conversation on the comments I believe that the issue is that you are using a topic that contains all the users, which is the my-groupchat topic. The solution would be to create a new topic with the users that are part of this subtopic.
As for how to create such topics, there are a couple of examples in this documentation, in there you can see that you could do it server side, or client side. In your case, you could follow the examples for the server side, since you would need to add them in bulk, but as new users are added it could be interesting to implement the client side approach.
I have an android app and want people (authenticated users) to send push notification each other from a message box. I'm using node.js with firebase cloud functions and I got this error on logs:
TypeError: Cannot read property 'userId' of undefined
at exports.sendNotification.functions.database.ref.onWrite.event (/user_code/index.js:10:33)
...
The message is successfully written to real-time database but the notification is not delivered to the receiver(user).
I read so many docs and same/similar problems so I'm aware that there are so many topics related to this but I couldn't solve the problem. I use index.js as the source code but changed some parts like onWrite section according to the documents I read.
The error indicates this line in the following code:
const receiverId = context.params.userId;
Something about params go wrong. Here is the small part of the code(with my changings):
let functions = require('firebase-functions');
let admin = require('firebase-admin');
admin.initializeApp();
exports.sendNotification = functions.database.ref('/messages/{userId}/{messageId}').onWrite((change,context) => {
//get the userId of the person receiving the notification because we need to get their token
const receiverId = context.params.userId;
console.log("receiverId: ", receiverId);
//get the user id of the person who sent the message
const senderId = change.child('user_id').val();
console.log("senderId: ", senderId);
//get the message
const message = change.child('message').val();
console.log("message: ", message);
//get the message id. We'll be sending this in the payload
const messageId = context.params.messageId;
console.log("messageId: ", messageId);
...
Get lastest version of node
And see this: https://firebase.google.com/docs/functions/database-events#handle_event_data for usage of onWrite(event...) and onCreate(.....)
That'll help you
I am able to send message to specific users with older botbuilder SDK 3.13.1 by saving message.address field in database.
var connector = new builder.ChatConnector({
appId: process.env.MicrosoftAppId,
appPassword: process.env.MicrosoftAppPassword,
openIdMetadata: process.env.BotOpenIdMetadata
});
var bot = new builder.UniversalBot(connector);
var builder = require('botbuilder');
var msg = new builder.Message().address(msgAddress);
msg.text('Hello, this is a notification');
bot.send(msg);
How can this be done with botbuilder SDK 4? I am aware of the Rest API but want to achieve this with the SDK itself because the SDK is the more preferred way of communication between the bot and user.
Thanks in advance.
Proactive Messages in the BotFramework v4 SDK enable you to continue conversations with individual users or send them notifications.
First, you need to import TurnContext from the botbuilder library so you can get the conversation reference.
const { TurnContext } = require('botbuilder');
Then, in the onTurn method, you can call the getConversationReference method from TurnContext and save the resulting reference in a database.
/**
* #param {TurnContext} turnContext A TurnContext object representing an incoming message to be handled by the bot.
*/
async onTurn(turnContext) {
...
const reference = TurnContext.getConversationReference(turnContext.activity);
//TODO: Save reference to your database
...
}
Finally, you can retrieve the reference from the database and call the continueConversation method from the adapter to send specific users a message or notification.
await this.adapter.continueConversation(reference, async (proactiveTurnContext) => {
await proactiveTurnContext.sendActivity('Hello, this is a notification')
});
For more information about proactive messages, take a look at the documentation or this example on GitHub. Hope this is helpful.
I've built out an integration using DocuSign's Node SDK. While testing using a DocuSign sandbox account, the authentication flow works just fine using the example in the docs.
I'm now trying to do the same within a live DocuSign production account using the Integrator Key that was promoted from the sandbox account. authApi.login() seems to work just fine, I get no error and the status code of the response is 200. However, the value of loginInfo comes back as exports {} with no account info included.
I've made sure to change the base path from https://demo.docusign.net/restapi to www.docusign.net/restapi and as far as I can tell from the docs, there doesn't seem to be anything else I need to make the switch to production. Here is the code I am using:
apiClient.setBasePath('www.docusign.net/restapi');
apiClient.addDefaultHeader('Authorization', 'Bearer ' + token);
docusign.Configuration.default.setDefaultApiClient(apiClient);
const authApi = new docusign.AuthenticationApi();
const loginOps = {
apiPassword: true,
includeAccountIdGuid: true
};
authApi.login(loginOps, function (err, loginInfo, response) {
if (err) {
console.log(err);
}
if (loginInfo) {
// loginInfo returns 'exports {}' so the variables below cannot be set.
const loginAccounts = loginInfo.loginAccounts;
const loginAccount = loginAccounts[0];
const baseUrl = loginAccount.baseUrl;
const accountDomain = baseUrl.split('/v2');
const accountId = loginAccount.accountId;
apiClient.setBasePath(accountDomain[0]);
docusign.Configuration.default.setDefaultApiClient(apiClient);
www.docusign.net endpoint will only work if your PROD account is in NA1, if your PROD Account is in NA2, then you need to use na2.docusign.net and if it is in NA3 then na3.docusign.net. This is the main reason you should use /oauth/userinfo call with OAUTH2 Access Token to know your base URL, and then call all APIs with this baseURL. You can find more details at https://docs.docusign.com/esign/guide/authentication/userinfo.html