onIncomingMessage on Sinch-rtc never gets called on receiving Sinch IM message - sinch

I am using NodeJS and Sinch-RTC (for IM feature) and I am unable to receive IM messages on my server - Meaning my onIncomingMessage is never called even though a message is sent to my username via phone. I am using the following code on my server.
var SinchClient = require('sinch-rtc');
var sinchClient = new SinchClient({
applicationKey: 'MY-APP-KEY',
capabilities: {messaging: true, calling: true},
supportActiveConnection: true,
});
var messageClient = sinchClient.getMessageClient();
sinchClient.start({username: 'MY_USERNAME', password: 'MY_PASSWORD'}).then(function() {
console.log('Success!');
global_username = username;
}).fail(handleFail)
var handleFail = function() {console.log("Message Sending failed");};
var eventListener = {
onIncomingMessage: function(message) {
console.log( message.textBody);
}
}
messageClient.addEventListener(eventListener);
When I run this program as "node sinchReceive.js" I am unable to receive any sinch message sent to MY_USERNAME. However, I can send a message to a different username and that doesn't have any problem. Please tell me what could be wrong or if I am missing something. Thanks.

Related

Parse Cloud Code Queries do not return anything ever

I have some parse cloud code im running on my self hosted server but im running into an issue where queries are not doing anything. I can run commands through terminal and get data back but when I run a query.find.. nothing happens. For Example:
Parse.Cloud.job("getall", function(request, response) {
var itemStatus = Parse.Object.extend('MovieStatus');
var query = new Parse.Query(itemStatus);
query.find({
success: function(results) {
console.log(results.length)
response.success(results.length);
},
error: function(err) {
response.error(err);
},
useMasterKey : true
})
})
Nothing happens. No error no response. I have added console logs to make sure its at least getting called and it is, but for some reason nothing every returns from the server when I do query.find
I have tried all sorts of things to figure out what the issue is but this affects all of my cloud code so it has to be something in there.
You are using an old syntax. Since version 3.0, Parse Server supports async/await style. Try this:
Parse.Cloud.job("getall", async request => {
​const { log, message } = request;
const ItemStatus = Parse.Object.extend('MovieStatus');
const query = new Parse.Query(ItemStatus);
const results = await query.find({ useMasterKey: true });
log(response.length);
message(response.length);
})
Not this is a job and not a cloud code function. You can invoke this job using Parse Dashboard and you should see the message in the job status section.

Sinch API JS, instant messaging. User creation is disabled for this application

I'm trying to create user for start instant messaging
$('button#register').on('click', function(event){
event.preventDefault();
$('button#register').attr('disabled', true);
clearError();
var signUpObj = {};
signUpObj.username = $('input#username').val();
signUpObj.password = $('input#password').val();
sinchClient.newUser(signUpObj, function(ticket) {
sinchClient.start(ticket, function() {
global_username = signUpObj.username;
localStorage[sessionName] = JSON.stringify(sinchClient.getSession());
}).fail(handleError);
}).fail(handleError);
})
But I'm receiving error message
errorCode: 40303
message: User creation is disabled for this application
So, what I should done?
In the dashboard of you app (sinch.com/dashboard), enable js auth

Push via parse server cloud code: Url not found

After working with Parse for a considerable time on multiple project I recently started moving data to a local Parse server and writing a sample app to get familiar with the system. I managed to get most working so far including Push using het Parse Dashboard.
Unfortunately I can't seem to get Parse Push to work using cloud code.
This is my code:
Parse.Cloud.define('push', function(req, res) {
var logMessage = "Push test";
console.log(logMessage);
var pushQuery = new Parse.Query(Parse.Installation);
Parse.Push.send({
where: pushQuery,
data: {
alert: 'Test'
}
}, {
useMasterKey: true,
success: function() {
// Push sent, send re
res.success('Push Sent');
var logMessage = "Push Sent!";
console.log(logMessage);
},
error: function(error) {
res.error(error)
var logMessage = error;
console.log(logMessage);
// There was a problem :(
}
});
var logMessage = "Push should be sent.";
console.log(logMessage);
});
Unfortunately no push is sent and the following error message is returned:
{
code: 107,
message: 'Received an error with invalid JSON from Parse: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">\n<html><head>\n<title>404 Not Found</title>\n</head><body>\n<h1>Not Found</h1>\n<p>The requested URL /push was not found on this server.</p>\n<hr>\n<address>Apache/2.4.7 (Ubuntu) Server at localhost Port 80</address>\n</body></html>\n' }
It seems to indicate the push request is sent to the /push directory of the main server, however I have no clue how I can change this to the appropriate location and I presumed parse-server would automatically choose the right path.
I hope someone might know how to fix this because I'm out of ideas at the moment..
For all that deal with this same issue, here is the solution.
Thanks to Anbarasi for the correct answer. My server settings were incorrect. Upon changing the server URL to the correct settings (address + port) everything started working!

reCAPTCHA timing out on verify

Having made no changes (but also not tested this in a couple months), my reCAPTCHA code is timing out when trying to verify the user response (both on localhost and on our DEV server). The IP is rotating in the error message (216.58.218.228:443, 172.217.1.4:443, others). I would normally think that this is a firewall issue - I can't telnet to the IP/Port combinations in the error messages - but I can pull up https://www.google.com/recaptcha/api/siteverify in a browser and get an error response back quickly. Any ideas on what might be going on?
Code I normally use:
// Prepare input.
var input = new NameValueCollection
{
{ "response", captcha },
{ "secret", _settings.SecretKey }
};
// Make call.
byte[] response;
using (WebClient client = new WebClient())
{
response = client.UploadValues(_settings.VerificationUrl, Http.Verbs.POST, input);
}
// Parse response.
var body = Encoding.UTF8.GetString(response);
var result = JsonConvert.DeserializeObject<VerificationResponse>(body);
return result.Success;
Attempt at verifying through GET (as recommended here):
using (WebClient client = new WebClient())
{
var response = client.DownloadString($"https://www.google.com/recaptcha/api/siteverify?secret={_settings.SecretKey}&response={captcha}");
}
Example full error message:
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 216.58.218.228:443

slack api rtm direct message

I'm using a node package: slack-client to interact with the api at slack. Now with or without using slack-client how do I send a direct message from my bot to a user I want to specify? Here's what have so far with a plain socket connection:
var WebSocket = require('ws')
,ws2 = new WebSocket(myURL); //from rtm start
ws2.on('open', function() {
ws2.send({
"id": 333,
"type": "message",
"channel": "#user1", //User I want to send to
"text": "HEY!!!!"
});
});
ws2.on('message', function(message) {
console.log('received: %s', message);
});
I was hoping that message would go directly to me from the bot but nothing. I get a reply of type hello though? The send details above I got on another post about this but it doesn't work for me. The message Id was one I created.
Ok so when calling the rtm.start via the web api, you would get a list of DM's that would be open for various users otherwise you can easily just open an im with im.open. I'm using the node package slack-client as mentioned in my question so you can do this:
//name of user your bot wants to send a msg to.
var userTest = slack.getUserByName('user1');
slack.openDM(userTest.id, function(res)
{
TestMsg(res.channel.id, 'some other msg');//test function I'm using
});
Next is the TestMsg function:
function TestMsg(userChannelId, msg)
{
request.post({url: 'https://slack.com/api/chat.postMessage',
form: { token: "xxxx-yourbot-token",channel: userChannelId,text: msg ,username: "yourBotNamehere", as_user: false}
}, function(error, response, body){
console.log(response.body);
});
}
I couldn't get it to work yet using the websockets send method but I suppose the api of postMessage will do for now as you can post richly formatted messages with postMessage. Hope this helps someone

Resources