Sir I wanted to ask if there is a way to identify if a topic belongs to a particular group. For ex: consider there is a user who is not in NMS_Jaipur, user can read the topics there but cannot create one, similarly for each topic in a group he is not a member of, he cannot post anything. But this user can create topics that dont belong to a group and are available for public discussion. I just want to know is there any parameter which distinguishes these topics?
Lets say when topic is created, by default the topic is present into the uncategorized category.
So to find out id of uncategorized group, get all categories (http://localhost:9292/categories.json) api need to be used
now i come to your question that how we can identify public topics which are accessible to all registered users. right.
so if topic is present in uncategorized category then it is accessible to all members and it is publicly available and if it is not present means you to check which is the category and whether user is a member of that category or not and if user is member of that category then check what permission user have. lets say reply or see or create. likewise you have to check.
function pvt_msg(req,res){
var title=req.body.title;
var category=req.body.category;
var desc=req.body.desc;
var user=req.body.user_search;
var url=secrets.url+'/posts.json';
var options={
method:"POST",
headers:{
'Api-Key': secrets.key,
'Api-Username': req.session.user.username
}
};
https.get(secrets.url+'users/'+req.body.user_search+'.json',(response)=>{
console.log(response.statusCode);
if(response.statusCode===200){
var det='';
response.on('data',(chunk)=>{
det+=chunk;
});
response.on('end',()=>{
det=JSON.parse(det);
console.log(det);
var data1= { "title": title,
"raw": desc,
"category": Number(category),
"target_recipients":det.user.username,
"archetype": "private_message"
};
console.log(data1);
var request=https.request(url,options,(response)=>{
console.log(response.statusCode);
if(response.statusCode===200){
var body='';
response.on('data',(data)=>{
body+=data;
});
response.on('end',()=>{
body=JSON.parse(body);
console.log(body);
res.redirect('/post/t/'+body.topic_slug+'/'+body.topic_id+'/1');
});
}else{
res.redirect('/');
}
});
request.write(querystring.stringify(data1));
request.end();
});
}else{
res.redirect('/');
}
});
}
Sir I was trying to create a private message, but I am getting status code 422 in the POST request.
200
{
user_badges: [],
user: {
id: 1111,
username: '1test1',
name: 'tester',
avatar_template: '/letter_avatar_proxy/v4/letter/1/3da27b/{size}.png',
last_posted_at: null,
last_seen_at: null,
created_at: '2020-06-10T16:34:48.853Z',
ignored: false,
muted: false,
can_ignore_user: false,
can_mute_user: false,
can_send_private_messages: false,
can_send_private_message_to_user: false,
trust_level: 0,
moderator: false,
admin: false,
title: null,
badge_count: 0,
user_fields: { '1': 'Teacher' },
custom_fields: {},
time_read: 0,
recent_time_read: 0,
primary_group_id: null,
primary_group_name: null,
primary_group_flair_url: null,
primary_group_flair_bg_color: null,
primary_group_flair_color: null,
featured_topic: null,
can_edit: false,
can_edit_username: false,
can_edit_email: false,
can_edit_name: false,
uploaded_avatar_id: null,
pending_count: 0,
profile_view_count: 1,
reminders_frequency: [ [Object], [Object], [Object], [Object], [Object] ],
geo_location: null,
featured_user_badge_ids: [],
invited_by: null,
groups: [],
group_users: [ [Object] ]
}
}
{
title: 'Hello Hello Test',
raw: 'testing bro how are you?',
category: 25,
target_recipients: '1test1',
archetype: 'private_message'
}
422
curl -X POST “https://t2.metastudio.org/posts.json”
-H “Content-Type: multipart/form-data;”
-H “Api-Key: 5b34278e6f1344a7a9909205e79418d0b4bceeiiiiiooeee”
-H “Api-Username: Siddhu_Dhangar”
-F “title=test messgae”
-F “raw=testing bro how are you?”
-F “archetype=private_message”
-F “target_recipients=siddhu123”
I tested this posts api for sending the private message.
{“id”:9954,“name”:“Siddhu Dhangar”,“username”:“Siddhu_Dhangar”,“avatar_template”:“/user_avatar/t2.metastudio.org/siddhu_dhangar/{size}/508_2.png”,“created_at”:“2020-06-17T06:18:42.801Z”,“cooked”:“\u003cp\u003etesting bro how are you?\u003c/p\u003e”,“post_number”:1,“post_type”:1,“updated_at”:“2020-06-17T06:18:42.801Z”,“reply_count”:0,“reply_to_post_number”:null,“quote_count”:0,“incoming_link_count”:0,“reads”:0,“readers_count”:0,“score”:0,“yours”:true,“topic_id”:3045,“topic_slug”:“test-messgae”,“display_username”:“Siddhu Dhangar”,“primary_group_name”:null,“primary_group_flair_url”:null,“primary_group_flair_bg_color”:null,“primary_group_flair_color”:null,“version”:1,“can_edit”:true,“can_delete”:false,“can_recover”:false,“can_wiki”:true,“user_title”:null,“actions_summary”:[{“id”:3,“can_act”:true},{“id”:4,“can_act”:true},{“id”:8,“can_act”:true},{“id”:7,“can_act”:true}],“moderator”:false,“admin”:true,“staff”:true,“user_id”:223,“draft_sequence”:0,“hidden”:false,“trust_level”:1,“deleted_at”:null,“user_deleted”:false,“edit_reason”:null,“can_view_edit_history”:true,“wiki”:false,“reviewable_id”:null,“reviewable_score_count”:0,“reviewable_score_pending_count”:0,“can_accept_answer”:false,“can_unaccept_answer”:false,“accepted_answer”:false}
it sent the message successfully. Initially i tried at that time i got 422 response because i passed raw parameter with value but the length of the raw must be greater than 20 characters. after i changed the raw value then it gives me 200 response.
try and let me know if have any doubt
{
title: 'lets us discuss pvt messages',
raw: 'hello trying to send you a test message',
target_recipients: '1test1',
archetype: 'private_message'
}
422
I am still getting 422 even after sending more that 20 characters to raw
curl -X POST “https://t2.metastudio.org/posts.json”
-H “Content-Type: multipart/form-data;”
-H “Api-Key: 54a7a9909205e79418d0b4bceesssssssssssssssssssssssssssssss”
-H “Api-Username: Siddhu_Dhangar”
-F “title=test messgae”
-F “raw=testing bro how are you?”
-F “archetype=private_message”
-F “target_recipients=1test1”
I sent message to 1test1 user. and it was sent successfully. Try to remove category parameter if it is being passed.
even i tested below code this one also working fine.
curl -X POST “https://t2.metastudio.org/posts.json”
-H “Content-Type: multipart/form-data;”
-H “Api-Key: 547da0e3edea4ebd10bfckjjkhhje79418d0b4bcee”
-H “Api-Username: Siddhu_Dhangar”
-F “title=lets us discuss pvt messages”
-F “raw=hello trying to send you a test message”
-F “archetype=private_message”
-F “target_recipients=1test1”
curl -X POST “https://t2.metastudio.org/posts.json”
-H “Api-Key: asasuasasasasas”
-H “Api-Username: Siddhu_Dhangar”
-F “title=lets us discuss pvt message 1”
-F “raw=hello trying to send you a test message”
-F “archetype=private_message”
-F “target_recipients=1test1”
{
title: 'testing testing pvt msg',
raw: 'hello hello test test pvt msg testing',
target_recipients: '1test1',
archetype: 'private_message'
}
422
Still getting 422 even after removing category and adding content type
give me some time i will check your js code in my system and i will let you know.
function pvt_msg(title,desc,user){
var title=title;
// var category=req.body.category;
var desc=desc;
var user=user;
var url=secrets.url+’/posts.json’;
var options={
method:“POST”,
headers:{
‘Api-Key’: secrets.key,
‘Api-Username’: “system”
}
};
var data1= {
“title”: title,
“raw”: desc,
“target_recipients”:“1test1”,
“archetype”: “private_message”
};
var request=https.request(url,options,(response)=>{
console.log(response.statusCode);
if(response.statusCode===200){
var body=’’;
response.on(‘data’,(data)=>{
body+=data;
});
response.on(‘end’,()=>{
body=JSON.parse(body);
// console.log(body);
// res.redirect(’/post/t/’+body.topic_slug+’/’+body.topic_id+’/1’);
});
}else{
res.redirect(’/’);
}
});
request.write(querystring.stringify(data1));
request.end();
}
pvt_msg(“testing testing pvt msg”,“hello hello test test pvt msg testing”,“1test1”)
i modified your code little bit and tried out modified code it is working fine. Can you test it again ?
function pvt_msg(title,desc,user){
var title=title;
// var category=req.body.category;
var desc=desc;
var user=user;
var url=secrets.url+‘/posts.json’;
var options={
method:“POST”,
headers:{
‘Api-Key’: secrets.key,
‘Api-Username’: ‘system’
}
};
https.get(secrets.url+‘users/’+user+‘.json’,(response)=>{
console.log(response.statusCode);
if(response.statusCode===200){
var det=‘’;
response.on(‘data’,(chunk)=>{
det+=chunk;
});
response.on(‘end’,()=>{
det=JSON.parse(det);
console.log(det);
var data1= { “title”: title,
“raw”: desc,
// “category”: Number(category),
“target_recipients”:det.user.username,
“archetype”: “private_message”
};
console.log(data1);
var request=https.request(url,options,(response)=>{
console.log(response.statusCode);
if(response.statusCode===200){
var body=‘’;
response.on(‘data’,(data)=>{
body+=data;
});
response.on(‘end’,()=>{
body=JSON.parse(body);
//console.log(body);
//res.redirect(‘/post/t/’+body.topic_slug+‘/’+body.topic_id+‘/1’);
});
}else{
res.redirect(‘/’);
}
});
request.write(querystring.stringify(data1));
request.end();
});
}else{
res.redirect(‘/’);
}
});
}
pvt_msg(“testing testing pvt msg”,“hello hello test test pvt msg testing”,“1test1”)
I tried this code also. i got 200 response when i ran this code.
function pvt_msg(req, res) {
var title = req.body.title;
// var category=req.body.category;
var desc = req.body.desc;
var user = req.body.user_search;
var url = secrets.url + '/posts.json';
var options = {
method: 'POST',
headers: {
'Api-Key': secrets.key,
'Api-Username': req.session.user.username
}
};
https.get(secrets.url + 'users/' + user + '.json', (response) => {
if (response.statusCode === 200) {
var det = '';
response.on('data', (chunk) => {
det += chunk;
});
response.on('end', () => {
det = JSON.parse(det);
var data1 = {
'title': title,
'raw': desc,
// “category”: Number(category),
'target_recipients': det.user.username,
'archetype': 'private_message'
};
console.log(data1);
var request = https.request(url, options, (response) => {
console.log(response.statusCode);
if (response.statusCode === 200) {
var body = '';
response.on('data', (data) => {
body += data;
});
response.on('end', () => {
body = JSON.parse(body);
console.log(body);
//res.redirect(’/post/t/’+body.topic_slug+’/’+body.topic_id+’/1’);
res.redirect('/');
});
} else {
res.redirect('/');
}
});
request.write(querystring.stringify(data1));
request.end();
});
} else {
res.redirect('/');
}
});
}
I copied your code and try to run it, but still for me it gives 422.
{
title: 'Let us meet some day',
raw: 'hello friend, let us meet some day to discuss about life over a cup of coffee',
target_recipients: '1test1',
archetype: 'private_message'
}
422
i will share my api key with you on telegram and try to replace your api key with my api key.test it again.
function reply(slug,id,content,user,res){
var url = secrets.url + '/posts.json';
var options = {
method: 'POST',
headers: {
'Api-Key': secrets.key,
'Api-Username': 'system'
}
};
var data1={
"topic_id": Number(id),
"raw": content,
'target_recipients': user,
"archetype": "private_message",
};
console.log(data1);
var request=https.request(url,options,(response)=>{
var body='';
console.log(response.statusCode);
if(response.statusCode===200){
response.on('data',(chunk)=>{
body+=chunk;
});
response.on('end',()=>{
body=JSON.parse(body);
console.log(body);
res.redirect('/chat');
});
}
});
request.write(querystring.stringify(data1));
request.end();
res.redirect('/chat');
}
I am trying to reply to a private message, but it is giving status code 422, kindly help sir.
ok. i will test it and let you know.
function reply(slug,id,content,user){
var url = secrets.url + '/posts.json';
var options = {
method: 'POST',
headers: {
'Api-Key': secrets.key,
'Api-Username': 'system',
}
};
var data1={
"topic_id": Number(id),
"raw": content,
'target_recipients': user,
"archetype": "regular"
};
console.log(data1);
var request=https.request(url,options,(response)=>{
var body='';
console.log(response.statusCode);
if(response.statusCode===200){
response.on('data',(chunk)=>{
body+=chunk;
});
response.on('end',()=>{
body=JSON.parse(body);
console.log(body);
// res.redirect('/chat');
});
}
});
request.write(querystring.stringify(data1));
request.end();
// res.redirect('/chat');
}
reply(2980,"reply to this message","Siddhu_Dhangar")
I slightly modified the above code. Can you test it out again ? and let me know if you have any doubt.
Thanks, it worked.
Sir, do we really need the other user details, since we have already created a private thread?
Can you elaborate your question ? i did not understand it.