Closed teegwende closed 6 years ago
@teegwende can you put all your codes? related to both cases.
and state the problems you face
@teegwende Could you provide a test case? i.e. the steps to reproduce the bug: start the social backend, send a curl command...
it's the same code for PhoneMessageRecipient and IdMessageRecipient. the line with instruction to create IdMessageRecipient is commented. in the code you must see this PhoneMessageRecipient recipient = new PhoneMessageRecipient(messageReceiver); //IdMessageRecipient recipient = new IdMessageRecipient(messageReceiver);
Now when i run test with curl i use phone number if it's PhoneMessageRecipient which is implemented and facebook id if it's the second one
Here the test commands
curl -X POST -d "user_id=+22670979788&channel=facebook&message=yibeogo" http://localhost:8080/SocialBackend/socials
or curl -X POST -d "user_id=10202955784933521&channel=facebook&message=yibeogo" http://localhost:8080/SocialBackend/socials
OK, I found the code. Please make approprite indentation to make the code more readable. What is the page token? and don't you need to specify something from the sender?
The search on this error would show up the following page: it says that it is due to Bad Parameter Errors. Can you check all input parameters of this call? https://developers.facebook.com/docs/messenger-platform/reference/send-api/error-codes/
public void sendFacebookMessage(/String userSender,/ String userReceiver, /String receiverProfile,/ String message) { PhoneMessageRecipient recipient = new PhoneMessageRecipient(userReceiver); Message msg; msg = new Message(message);
String pageAccessToken = "EAAXh1hmHeq4BAIekZAddN3lvuKPzRCERfNmdT9B4oKJ8vC0OZCGl2a1GYty8nZB5ZBifhbBbbK3yNrqzgv0YTk3BDyQK9HjLnMFiZA4hJKdIGVgo9HHZC9VH0ZAO9rEx5zE7GmJZASoGZAlj1rnuuFN6qf6sZAqvSwqZC1Xo4JrOQyvnQZDZD";
FacebookClient pageClient = new DefaultFacebookClient(pageAccessToken, Version.VERSION_2_6);
pageClient.publish("me/messages", SendResponse.class,
Parameter.with("recipient", recipient),
Parameter.with("message", msg ));
}
Check this https://github.com/howdyai/botkit/issues/312 out.
Also please check the following https://github.com/jgorset/facebook-messenger/issues/62 A quote from that page "This issue was caused by an invalid PAGE_ACCESS_TOKEN on my side, my mistake was that I recreated the token and they look very similar. Please make sure this token is exactly the same."
This can help also
@teegwende can you provide a link to facebook document thta you used?
restfb documentation http://restfb.com/documentation/
facebook send api documentation https://developers.facebook.com/docs/messenger-platform/send-messages
I reproduced the error this way:
$ mvn install wildfly-swarm:run
$ curl -H "Content-Type:application/json" -X POST -d '{"user_id": "corentin.dupont1", "channel":"facebook","message":"Yibeogo Ouaga","username":"Pandaconstantin"}' http://localhost:9123/api/v1/domains/waziup/socials
com.restfb.exception.FacebookOAuthException: Received Facebook error response of type OAuthException: (#100) No matching user found (code 100, subcode 2018001)
It seems you cannot send direct messages to users (as anti-spam measure). You can only reply to messages the user sends you. So instead, I propose to send messages to the waziup feed. If you agree, I'll close this issue and open another.
i use restfb api to send messages. The documentation says it possible to do this by either using webhooks or Send API. i use the second one. To use Send API we have to create a message and a recipient. There are two kind of recipients : IdMessageRecipient and PhoneMessageRecipient. The first one is an object created by using facebook id and the second is object created by using a phone number tied to a facebook account.
I have implemented PhoneMessageRecipient. it's working with only users i have designated as testers. I would like to be able to send message to anybody logging on waziup dashboard through his facebook login. For that i would like to use IdMessageRecipient. But when i implemented it and try to send a message i have an issue (#100) No matching user found (code 100, subcode 2018001)
it seems setting up webhook is another possiblity to handle this problem. but i have no idea to this.
here is my code
public void sendFacebookMessage(String messageReceiver, String message) {
String pageAccessToken = "EAAXh1hmHeq4BAIekZAddN3lvuKPzRCERfNmdT9B4oKJ8vC0OZCGl2a1GYty8nZB5ZBifhbBbbK3yNrqzgv0YTk3BDyQK9HjLnMFiZA4hJKdIGVgo9HHZC9VH0ZAO9rEx5zE7GmJZASoGZAlj1rnuuFN6qf6sZAqvSwqZC1Xo4JrOQyvnQZDZD";
FacebookClient pageClient = new DefaultFacebookClient(pageAccessToken, Version.VERSION_2_6); pageClient.publish("me/messages", SendResponse.class, Parameter.with("recipient", recipient), // the id or phone recipient Parameter.with("message", msg /+""+ fetchObject/)); // one of the messages from above }