Unable to add users to existing chat in Quickblox JS - quickblox

I have added a feature to QuickBlox chat sample for JS , which allows to add a new user to existing chat
function addUsers(){
var curDlgId = currentDialog._id ;
var curDlgName = currentDialog.name;
$('.users_form.active').each(function(index) {
users_ids[index] = $(this).attr('id');
});
QB.chat.dialog.update(curDlgId,{ push_all : {users_ids}}, onAddUsersCompleted);
}
function onAddUsersCompleted(error,b,c){
}
but I am getting an error on onAddUsersCompleted callback :
error = Object {code: 403, status: "error", message: "Forbidden", detail: "{"errors":["You don't have appropriate permissions to perform this operation"]}"}
Whats wrong ?

Ostap, please try to change
QB.chat.dialog.update(curDlgId,{ push_all : {users_ids}}, onAddUsersCompleted);
to
QB.chat.dialog.update(curDlgId,{ push_all : users_ids}, onAddUsersCompleted);

Related

I am trying to get data over an OpenWeather API in Rust but I am facing some iusse regarding parsing I guess

extern crate openweather;
use openweather::LocationSpecifier;
static API_KEY: &str = "e85e0a3142231dab28a2611888e48f22";
fn main() {
let loc = LocationSpecifier::Coordinates {
lat: 24.87,
lon: 67.03,
};
let weather = openweather::get_current_weather(loc, API_KEY).unwrap();
print!(
"Right now in Minneapolis, MN it is {}K",
weather.main.humidity
);
}
error : thread 'main' panicked at 'called Result::unwrap() on an
Err value: ErrorReport { cod: 0, message: "Got unexpected response:
\"{\\"coord\\":{\\"lon\\":67.03,\\"lat\\":24.87},\\"weather\\":[{\\"id\\":803,\\"main\\":\\"Clouds\\",\\"description\\":\\"broken
clouds\\",\\"icon\\":\\"04n\\"}],\\"base\\":\\"stations\\",\\"main\\":{\\"temp\\":294.15,\\"pressure\\":1018,\\"humidity\\":60,\\"temp_min\\":294.15,\\"temp_max\\":294.15},\\"visibility\\":6000,\\"wind\\":{\\"speed\\":5.1,\\"deg\\":30},\\"clouds\\":{\\"all\\":70},\\"dt\\":1574012543,\\"sys\\":{\\"type\\":1,\\"id\\":7576,\\"country\\":\\"PK\\",\\"sunrise\\":1573955364,\\"sunset\\":1573994659},\\"timezone\\":18000,\\"id\\":1174872,\\"name\\":\\"Karachi\\",\\"cod\\":200}\""
}
The issue is a JSON parsing error due to the deserialized struct not matching OpenWeather's JSON, perhaps the API recently added this? With your example, the OpenWeatherCurrent struct is missing timezone.
But it looks like there is an open PR that will fix this, you can test it by doing the following:
Change your Cargo.toml dependency to openweather = { git = "https://github.com/caemor/openweather" }.
The PR author has also updated the get_current_weather signature so you'll need to change lines 2, 10 to the following:
use openweather::{LocationSpecifier, Settings};
let weather = openweather::get_current_weather(&loc, API_KEY, &Settings::default()).unwrap();

Twilio Programmable Voice isn't working

When i try to pass param from my application using [TwilioVoice Call] method i am not able to get those param on twiML application. but when i try to pass same data from POSTMAN with FormData its working fine and also successfully able to create call.
Would you please help me how can i use param passed from my iOS application into twiML
TwiML Application in PHP :
<?php
/*
* Makes a call to the specified client using the Twilio REST API.
*/
include('./vendor/autoload.php');
include('./config.php');
$to = isset($_GET["to"]) ? $_GET["to"] : "";
if (!isset($to) || empty($to)) {
$to = isset($POST["to"]) ? $_POST["to"] : "";
}
$from = isset($_GET["from"]) ? $_GET["from"] : "";
if (!isset($from) || empty($from)) {
$from = isset($POST["from"]) ? $_POST["from"] : "";
}
use Twilio\Twiml;
$response = new Twiml();
$dial = $response->dial(['callerId' => $from]);
$dial->client($to);
echo $response;
iOS Objective-C :
self.call = [TwilioVoice call:[self fetchAccessToken]
params:#{#"to": #"1",#"from":#"2"}
uuid:uuid
delegate:self];
Twilio Error Log when i try to pass param from iOS
Warning - 13224 Dial: Twilio does not support calling this number or the number is invalid
Reference TwiML Application Code
https://github.com/twilio/voice-quickstart-server-php
Twilio developer evangelist here.
The 12100 error comes from Twilio not being able to parse the TwiML returned from your server. In this case, it is because your PHP is not returning TwiML, it's trying to make a call using the REST API.
It should return a <Dial> with a nested <Client>. You can build this up using the helper library too. Try changing your code to this:
<?php
include('./vendor/autoload.php');
include('./config.php');
$to = isset($_REQUEST["To"]) ? $_REQUEST["To"] : "";
$to = str_replace("client:", "", $to);
$from = isset($_REQUEST["From"]) ? $_REQUEST["From"] : "";
use Twilio\Twiml;
$response = new Twiml();
$dial = $response->dial(['callerId' => $from]);
$dial->client($to);
echo $response;
Let me know if that helps.
Step 1. In the name you have to pass name of the user(any thing you want)
Step 2. You need to generate token using 3 parameters
Step 3. You need to create object of VoiceGrant
Step 4. You need to pass Id
Step 5. You need to set PUSH notification Id generate from twilio
$name = $this->input->post('name');
//$PUSH_CREDENTIAL_SID = 'CRaf1a66dd4a7656876e16c7820ef5c01e';
$outgoingApplicationSid = 'APf9b1b789ba690b8789d95a42511f2018';
// choose a random username for the connecting user
$identity = $name;
// Create access token, which we will serialize and send to the client
$token = new AccessToken(
$this->twilioAccountSid,
$this->twilioApiKey,
$this->twilioApiSecret,
3600,
$identity
);
// $chatGrant = new ChatGrant( $pushCredentialSid= "CRaf1a66dd4a7656876e16c7820ef5c01e");
//
// print_r($chatGrant);die;
// Create Chat grant
// $voiceGrant = new VoiceGrant($serviceSid = 'IS840a7e5f64634ab6bf179c3f8b0adfc4',$pushCredentialSid = 'CRaf1a66dd4a7656876e16c7820ef5c01e');
$voiceGrant = new VoiceGrant();
$voiceGrant->setOutgoingApplicationSid($outgoingApplicationSid);
// Optional: add to allow incoming calls
$voiceGrant->setIncomingAllow(true);
$voiceGrant->setPushCredentialSid('CRaf1a66dd4a7656876e16c7820ef5c01e');
// Add grant to token
$token->addGrant($voiceGrant);
// render token to string
$voice_token = $token->toJWT();
if($voice_token){
$data['token'] = $voice_token;
$this->response = array('status'=>1,'data'=>$data);
}else{
$this->response = array('status'=>0,'message'=>'Not found');
}

AssertionError: relay-101/index.js: getBabelRelayPlugin(): Expected schema to be an object with a `__schema`

I was following Relay 101: Building A Hacker News Client Tutorial.
But in the process I got error
AssertionError: relay-101/index.js: getBabelRelayPlugin():
Expected schema to be an object with a `__schema` property.
at getSchema (/Users/ruseel/p/spike/relay-101/node_modules/babel-relay-plugin/src/getBabelRelayPlugin.js:224:3)
at NodePath.Plugin.visitor.TaggedTemplateExpression (/Users/ruseel/p/spike/relay-101/node_modules/babel-relay-plugin/src/getBabelRelayPlugin.js:104:26)
...
and after little digging (console.log in getBabelRelayPlugin.js) I noticed introspection var in getBabelRelayPlugin.js
const introspection = typeof schemaProvider === 'function' ?
schemaProvider() :
schemaProvider;
is like this.
{"errors":[{"message":"Must provide query string."}]}
But I have no idea why this is happening?
Why is this error happening?
any direction would be appreciated.
I made a typo in babelRelayPlugin.js, instrospectionQuery instead of introspectionQuery.
var babelRelayPlugin = require('babel-relay-plugin');
var introspectionQuery = require('graphql/utilities').introspectionQuery;
var request = require('sync-request');
var graphqlHubUrl = 'http://www.graphqlhub.com/graphql';
var response = request('GET', graphqlHubUrl, {
qs: {
query: introspectionQuery
}
});

Titanium simple xhr POST of binary won't work

I am trying to do this curl post in Titanium but I keep getting a 400 error.
I have tried passing the data as a Javascript object. I tried also changing the header.
Maybe I haven't hit the right combination of things.
Please help.
curl 'https://ortc-mobilepush.realtime.co/mp/publish' --data-binary '{"applicationKey": "[INSERT_YOUR_APP_KEY]","privateKey": "[INSERT_YOUR_PRIVATE_KEY]",
"channel" : "NewArticles",
"message" : "We have new articles for you",
"payload" : "{ \"sound\" : \"default\", \"badge\" : \"2\" }" }'
var url = 'https://ortc-mobilepush.realtime.co/mp/publish';
var client = Ti.Network.createHTTPClient({
// function called when the response data is available
onload : function(e) {
Ti.API.info("Received text: " + this.responseText);
alert('success');
},
// function called when an error occurs, including a timeout
onerror : function(e) {
Ti.API.debug(e);
//alert('error');
},
timeout : 5000 // in milliseconds
});
client.open("POST", url);
client.setRequestHeader('Content-Type', 'multipart/form-data');
// Send the request.
var text = '{"applicationKey": "[App Key]","privateKey": "[Private key]", "channel" : "GlobalChanell", "message" : "test", "payload" : "{ \"sound\" : \"default\", \"badge\" : \"32\" }" }';
client.send(text);
recently I also faced same problem in one of my client application...
so i should give solution for that..
may be there is a problem of server url...so you can try to change that url and replace it with something below...
https://exampleserver.com/mp/publish
then set Content-Type to application/json
and create json object like below....
var text = {
applicationKey : [key],
privateKey : [p_key],
etc....
}
then pass it like....
client.send(JSON.stringify(text));

Strophe.attach not working - I am using openfire locally

I am trying to implment the XMPP Client. I am using BOSH Connection manager and can run the Strophe.connect but not Strophe.Attach. I have tried incrementing the RID, but no effect.. Any help please ? There is no error here, but the Strophe.Status.CONNECTED is never reached via the attach method and so I cannot send IQ or Presence.
Here is my code
try
{
var cookieJid = $.cookie("jid");
var cookieSid = $.cookie("sid");
var cookieRid = $.cookie("rid");
var connt = new Strophe.Connection("http://localhost:7070/http-bind/");
connt.attach(cookieJid, cookieSid, cookieRid + 1, function(status)
{
if (status === Strophe.Status.CONNECTED)
{
alert ("hola connected");
$("#userName").append("hola connected : " + connt.jid );
var iq = $iq({type: 'get'}).c('query', {xmlns: 'jabber:iq:roster'});
connt.sendIQ(iq, handleRoster);
connt.send($pres());
}
});
}
catch (e)
{
$("#userName").append("Pinky error is " + e);
}
Edit
Thanks Eric and Charlie.
So I took the latest Strophe.js and now Attached status does work.
But the connection disconnects instantaneously. I am not even able to fetch the Roster.
We can possibly do every thing with Connection.attach() as we would with connection.connect(), right?
Any thoughts?
Change the line:
if (status === Strophe.Status.CONNECTED)
...to...
if (status === Strophe.Status.CONNECTED || status === Strophe.Status.ATTACHED)
Are you using the latest Strophe library? In the version I'm using, I see that the status can be these values:
Status: {
ERROR: 0,
CONNECTING: 1,
CONNFAIL: 2,
AUTHENTICATING: 3,
AUTHFAIL: 4,
CONNECTED: 5,
DISCONNECTED: 6,
DISCONNECTING: 7,
ATTACHED: 8
}
Make sure you convert your cookieRid to a Number by using new Number(cookieRid). Otherwise, when you do +1 on it, you will get "####1".
You can test this out for yourself in Javascript:
var s = "123";
alert(s+1); // "1231" and not "124"
Also, as Eric answered, there is a status ATTACHED so you need to handle that event.