Cannot add members to existing room using openfire REST API - openfire

openfire 4.0.2
https://github.com/igniterealtime/REST-API-Client
I am using the REST API Client to add a user to a room.
Looking at the debug information it seems to return success 201. However, the user is not added to the chat room.
1 > POST http://10.10.20.160:9090/plugins/restapi/v1/chatrooms/coffeeroom/members/steve#localhost.localdomain
1 > Authorization: Basic YWRtaW46Zm9ydW0xOA==
1 > Content-Type: application/xml
Apr 06, 2016 12:31:51 AM org.glassfish.jersey.filter.LoggingFilter log
INFO: 1 * Client response received on thread http-nio-8080-exec-2
1 < 201
1 < Access-Control-Allow-Credentials: true
1 < Access-Control-Allow-Headers: origin, content-type, accept, authorization
1 < Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS, HEAD
1 < Access-Control-Allow-Origin: *
1 < Content-Length: 0
1 < Date: Tue, 05 Apr 2016 17:31:51 GMT
1 < Expires: Thu, 01 Jan 1970 00:00:00 GMT
1 < Set-Cookie: JSESSIONID=153sgnfp1oi1x16rjo68kvbwz8;Path=/;HttpOnly
1 < X-Frame-Options: deny
I have successfully created new group chat rooms using the REST API, but can't add any users into them. Using this code.
mRestXmppClient.getRestApiClient().addMember(roomName, username);
Just wondering for this to work do I need to add any particular setting for the users, rooms, roles to add a user into a chat room?
Under Permissions (Room Affiliations)
I have added steve#localhost.localdomain to the members of this room.
However, I am still not able to add a member to the group chat room. Am I missing something here? I am wondering if there is any settings that I need to modify for the room to get this to work. These are the properties of the room I am trying to add a member to.
Any extra help would be grateful.

I guess you misunderstood the flow/design how it works.
By adding a user e.g over REST API to a member/admin/outcast/owner list does NOT mean the user will be placed there as an occupant with this role/affiliation.
It means the user have only follow affiliation (be a normal member or admin etc.). Really good overview about MUC XMPP terms is the XEP: http://xmpp.org/extensions/xep-0045.html#terms-general
If you want to be an occupant, you need to connect to the server and also join the channel. After that you will present as an occupant with probably specific role.
I would recommend you to read more about Multi User Chat here: http://xmpp.org/extensions/xep-0045.html

Related

How do I use the "If-Modified-Since" in the Salesforce v55.0 Rest API?

According to the documentation:
"An optional header specifying a date and time. The request returns
records that have been modified after that date and time."
I am making a request to the following endpoint:
/services/data/v55.0/sobjects/Contact/{id}
With the following headers:
GET
Content-Type: "application/json" Authorization: "Bearer
{access_token}" "If-Modified-Since": Thu, 08 Sep 2022 16:54:10 GMT
The header of the response contains the "Last-Modified" date/time of the SObject row that I requested and the date is "Thu, 08 Sep 2022 15:54:10 GMT".
How is it possible that the api is returning the data of the contact if it has not been modified since the time in my request?
Note: When I change the date/time in my request to "Thu, 08 Sep 2022 15:54:11 GMT", I see the correct behaviour and a 304 Not Modified is returned. However, should the time be moved forward by an hour the data is returned with a 200 OK
This can be a bug in the server implementation.
Another explanation that the server time is not properly set. Looks like in the case of salesforce this is true. A possible workaround is strictly using the value they send in the Last-Modified header instead of the current time of the client's computer. https://salesforce.stackexchange.com/a/375976

Telegram Bot API: getChatMember throws USER_ID_INVALID for valid user

I'm trying to find out if a specific User is present in a supergroup, in order to keep track of those who left.
For that, I'm calling the Bot API method getChatMember for each User and checking if their status is either Left or Kicked. However, I noticed that (recently?) I'm getting USER_ID_INVALID errors for many valid users that are either in the supergroup or have been in the past and then left. I also confirmed that those accounts are still active on Telegram.
Here's the HTTP request I'm sending:
POST https://api.telegram.org/botXXXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXX/getChatMember HTTP/1.1
Connection: Keep-Alive
Content-Type: application/json; charset=utf-8
Content-Length: 46
Host: api.telegram.org
{"chat_id":-0000000000000,"user_id":000000000}
And here's the response I'm getting:
HTTP/1.1 400 Bad Request
Server: nginx/1.12.2
Date: Fri, 20 Apr 2018 04:17:32 GMT
Content-Type: application/json
Content-Length: 74
Connection: keep-alive
Access-Control-Allow-Origin: *
Access-Control-Expose-Headers: Content-Length,Content-Type,Date,Server,Connection
{"ok":false,"error_code":400,"description":"Bad Request: USER_ID_INVALID"}
Any way I look at it, it looks like a perfectly valid request to me. And I haven't been able to find a common pattern between the users that throw this error.
What am I missing here?
EDIT: As #sean pointed out, having one of those users message the bot privately fixed the error for that particular user. But I'm absolutely sure that user was seen before because that's how I got his user ID. What could have caused the bot "forget" about him and how would I prevent this from happening in the future?
This error means your bot haven't seen this user before.
For instance, my user ID is 109780439, you can try getChatMember with #PublicTestGroup, it should response with 400 error.
And then, forward ANY of my message (e.g., this) to your bot, you will see the different result :)
You will create a variable who get your channel's result, like this:
$join : api.telegram.org/botYOURTOKEN/getchat .....
if($message && (strpos($join,'"status":"left"') or strpos($join,'"Bad Request: USER_ID_INVALID"') or strpos($join,'"status":"kicked"'))!== false) {
}

DRF JSON Token Authentication

I have to implement following features with RESTAPI:
register user
authorize user and get token
get user data by token
create user's post via token (Title, Body)
get user's posts via token
get all posts via token
user profile has to be customized - main fields are email/password
models.py:
http://pastebin.com/8V7CzrVi
serializers.py:
http://pastebin.com/W7Dn8Msn
views.py:
http://pastebin.com/L5ijkd5F
urls.py:
urlpatterns = [
url(r'^api/', include('app.urls')),
]
app.urls:
from .views import Register, UserList, UserDetail, PostList, PostDetail
from rest_framework_jwt.views import obtain_jwt_token
urlpatterns = [
url(r'^users/$', UserList.as_view(), name='user-list'),
url(r'^users/(?P<pk>[0-9]+)/$', UserDetail.as_view(), name='user-detail'),
url(r'^posts/$', PostList.as_view(), name='post-list'),
url(r'^posts/(?P<pk>[0-9]+)/$', PostDetail.as_view(), name='post-detail'),
url(r'^login/', obtain_jwt_token),
url(r'^register/$', Register.as_view()),
]
First question - please, review the code and tell, am I right in my realization? (THANKS A LOT for any corrections, hints and explanations)
Second one - how can I perform creating the post or viewing of post's list without any client code?
I mean following:
I am going into browserable API at api/register, enter email and password, hit post and get object of user
then I am going at api/login, enter email and password of the user just registered, hit post and get object with token - {'token': 'sometoken'}
then I am trying to create the post or get post's list, using httpie. In the console I enter -
http POST 127.0.0.1:8000/api/posts "Authorization: Token sometoken"
or
http GET 127.0.0.1:8000/api/posts "Authorization: Token sometoken"
and get:
HTTP/1.0 301 MOVED PERMANENTLY
Content-Type: text/html; charset=utf-8
Date: Sat, 03 Sep 2016 10:22:33 GMT
Location: http://127.0.0.1:8000/api/posts/
Server: WSGIServer/0.1 Python/2.7.11
X-Frame-Options: SAMEORIGIN
I do not understand how I can check every endpoint with using token.
Thanks!!!

getting directly only the contents after the first nth character in vb.net

Is there any way we could get directly say the 1000 characters after the first 5000 characters, skipping everything before that after sending in an HTTP request to an HTTPS page using either GET or POST in VB.NET?
The reason why I ask this question is because in one of the webpage I am trying the get through my program, the website is sending response data in chunks with the first chunk containing some javascript garbage that I have no interest in, the only data I care is in the second chunk and
I have no idea how to get the second chunk after receiving the first one since it is within the same HTTP request
It would save some time and Internet traffic if I can skip the first chunk that I do not need.
Is that possible or I am just day dreaming?
Many thanks!
ADDED:
Here is how a typical header of the response I am getting from the webpage I am trying to get:
Date: Mon, 20 Jun 2011 13:21:56 GMT
Set-Cookie: JSESSIONID=1AF1AF9EF936E1CB2FA85B750EDC67C4; Path=****some path******; Secure
Content-Type: text/html; charset=ISO-8859-1
Transfer-Encoding: chunked
Set-Cookie: **********some cookie***************
path=/
Vary: Accept-Encoding, User-Agent
Not sure if that helps, but as you can see, the chunk size is not visible to me, there is no "Trailer" in the header as well.
Fun little problem. Look at RANGE in the following GET request.
GET /file.txt HTTP/1.1
Host: localhost
Range: bytes=5000-6000
Connection: Close
Edit: Found a HTTP example.
Here is an example in PHP. (Sorry I couldn't find any VB.NET examples).

For cache-control to expire in 10 years, is using doc.css?v=128 exactly the same as doc_v128.css?

When using Cache-Control and Expires header so that a page won't expire in 10 years:
Cache-Control: max-age=315360000
Expires: Sun, 19 Jul 2020 18:06:32 GMT
will using line 1 have identical result as line 2?
<link href="/public/doc.css?v=128" ... >
<link href="/public/doc_v128.css" ... >
I was thinking maybe some browser will take the ?v=128 as a somewhat more dynamic content and reload it before the 10 year expiration?
Otherwise, both files will expire in 10 years and when there is changes to the CSS, the 128 can be updated to 129 and it will be loaded for sure and have a brand new 10 year expiration date?
(the same goes for javascript .js files)
Using a changing value in the querystring may work against you. According to Google's Page Speed Optimize caching Performance Best Practice:
Don't include a query string in the URL for static resources
Most proxies, most notably Squid up
through version 3.0, do not cache
resources with a "?" in their URL even
if a Cache-control: public header is
present in the response. To enable
proxy caching for these resources,
remove query strings from references
to static resources, and instead
encode the parameters into the file
names themselves.
Also, you may want to reconsider 10 years. According to the Header Field Definitions > Expires section of RFC 2616, one year is the max.
To mark a response as "never expires,"
an origin server sends an Expires date
approximately one year from the time
the response is sent. HTTP/1.1 servers
SHOULD NOT send Expires dates more
than one year in the future.