Java Facebook Messenger Jar

20 views
Skip to first unread message
Message has been deleted

Travers Guliuzza

unread,
Jul 18, 2024, 3:53:08 AM7/18/24
to onflunerded

I am writing a java application in which I need to access my chat history (chat messages between me and another Facebook friend). I have looked at this link, but it seems outdated since I have noticed that Facebook changed his messenger API significantly. I was wondering if it is still possible to access my message history via java.

In order to use this from Java, you'll need to first follow the login instructions at -login/v2.3 . That's a large enough operation that I'm going to assume that you've already done it -- it's well outside the scope of this answer (but I'm sure there are other questions that handle it sufficiently on StackOverflow if you look).

Java Facebook Messenger Jar


Download Zip https://tinourl.com/2yLIVl



Once you have an access token for a particular session (you can get one to test with by going to -api/reference/v2.3/user/inbox, clicking the Graph Explorer button, clicking "Get Token" -> "Get Access Token", and ensuring that "read_mailbox" is selected under "Extended Permissions), it's pretty straightforward to read the API. You can do it using only standard JDK classes in just a few lines:

This glosses over a lot of things -- doesn't help with authentication, assumes your active trust store contains a certification path for the Facebook SSL cert (it should), and ignore proper error handling. And in practice you'll want to use RestClient or something similar instead of using URL directly -- but the above should be indicative of basically what you need to do.

After a research I found that making connection with facebook IS possible via Spring boot (as explained here: -facebook/ ) but I have not found any information or - even similar to the NodeJS - method to handle a messenger conversation using a Spring Boot server.

Is it possible to request and send facebook messenger messages from Spring Boot? I would prefer that over NodeJS, as I have a system already built in Spring Boot, and it would be much easier to integrate this feature there, than creating a new service, which would be then connected to the existing one. (even if in some cases I definitely would stuck with the 'microservice' structure.)

The main function of a Bot is to receive and reply messages. With JBot, receiving messages is as easy as just writing a simple @Controller and replying to it by calling the reply() method as shown below:

All the code for your bot goes in FbBot class which extends Bot from the core package. You can have as many bots as you want, just make the class extend Bot class and it gets all the powers of a Facebook Bot. Though it is recommended to have separate JBot instances for different bots.

In Facebook, we can make messenger bots for pages and not for users. To start using fb APIs, we need a page access token which can be generated from any of your fb app settings. This page access token needs to be specified in application.properties file in jbot-example. You can remove "slack" from the spring.profiles.active as well. After this, you can start the bot by running JBotApplication from your IDE or via command-line.

Once the bot is started, you can go to the app's setting and setup webhooks. Give the secure url to your bot applcation, you may use localtunnel.me to generate one if you're running on your machine and not on any server. You also need to provide a "Verify Token" which can be found in application.properties file in fbBotToken property.

Luckily, with JBot, you don't have to worry about defining your own handler to handle those POST calls, parsing the event etc. To receive events from Fb, you just have to define methods with @Controller annotation (from here on, we will call them as @Controller).

ii. Another example which adds a pattern to the @Controller. Adding a pattern will restrict the method to be invoked only when the event text or event payload (depending on the event type) matches the pattern defined. You can specify a regular expression in pattern.

You can optionally have a matcher as a formal parameter (after event) in the method if you want to work on the matched values sent by the user. You can access by matcher.group(0), matcher.group(1) etc.

One thing to note here, the pattern will be matched against the text or payload depending on the event type received. For the below example, the event received will be of type QUICK_REPLY and the pattern in this case will be matched against the payload attribute in QuickReply and not against the text attribute.

You can see all the webhook events that the messenger platform currently supports. You may see that there is no specific QUICK_REPLY event type listed there. This is an extra event added by JBot to make your task easier.

Like receiving, for sending messages to users from your bot you need to make POST calls to the Facebook's Send API. But again, with JBot, you can simply reply by calling the reply() method from within your @Controller method. There are various overloaded versions of the reply() method to suit your needs.

This is a differentiating feature of JBot, with this you can literally talk to your bot and have a conversation. See below for an example as to how your bot sets up a meeting for your team by asking some simple questions one after the other.

You can set the "Get Started" button by simply calling the setGetStartedButton("hi"); where "hi" is your payload. You can see the init() method in FbBot.java. Just uncomment the @PostConstruct after you've setup your webhook.

The greeting text allows you to specify a message people will see on the welcome screen of your bot. The welcome screen is displayed for people interacting with your bot for the first time. You can set the greeting text like:

NOTE: When you include jbot as a dependency please make sure to include me.ramswaroop.jbot package for auto-scan. For example, you can specify scanBasePackages in @SpringBootApplication or @ComponentScan. See jbot-example to learn more.

Last month I've joined the Facebook DevC family as DevC Casablanca Lead. Developer Circle is a community supported by Facebook, and aims creating active communities for developers around the world to access information, share knowledge, and collaborate with other developers.

As a DevC Lead, One of my roles is to encourage Moroccan Developers to participate to Bots for Messenger Challenge, but wait... how I'm supposed to do that if I've never developed a bot for messenger!! and this is how my bot journey starts.

I'm a JVM fan Boy, so the first thing I did was looking on Facebook documentation if there is a getting started guide using any of the many JVM langages! Unfortunately, none found. The official documentation showcase uses only nodeJS. So I did as any good developer would do, follow the doc and understand it using [yes, exactly!] NodeJS. Once done, I started searching for any java library that could help me during my journey, and hope, I found it. It's called Messenger4J. Good, solid and simple library that covers my need.

I like Spring Boot and how it makes our lives, as developers, much easier, productive and straightforward to get things done. Which says, I spent so much time on the spring Documentation website, and from here comes my idea: Why not developing a bot, that simplifies things more [Btw, I'm a lazy developer], and all what I need is to type a text, and the bot return back the top articles. It'd be fun, isn't ? here is the final result:

Notice that if you typed anything except Yo or Great the bot well consider it as a search key (Not that clever, I know :P). I'm using Jsoup library, that makes a request to spring doc page and extracts its data:

First thing you need to do is to setup a Facebook app, Please follow this link for more details. You'll need also a free hosting service like Heroko or Clever Cloud, or you can simply use NGROK, and don't forget to create a Facebook page.

MODERATOR EDIT:
Attention for having bought an FCU and an MCDU in this company, I strongly advise, mediocre quality material, Baro button on the FCU did not work, and a button on the MCDU was blocked
Return to my charge delivery and customs fees and still no remborusement

Attention pour avoir achet un FCU et un MCDU dans cette societe, je deconseille fortement, materiel de qualite mediocre, bouton du Baro sur le FCU ne fonctionnait pas, et un bouton sur le MCDU etait bloqu
Retour ma charge livraison et frais douane et toujours pas de remborusement

How long did it take any of you to get your products? I placed an order for the MCDU a month and a half ago. Order still processing and no responses to my status uodate requests via facebook messenger.

Hi,
I have the Java OVH panel.
I have the same problem with the key mappings.
This is strange because before it worked very good (with exception of the known bugs with wiper knob and fuelbutton inidcator lights).
I hope it wil be updated soon.

Hi,
I have the OVH. The promissed delivery dates were not met several times. However, it did arrive. It was very nicely packaged and is very nice to use in the sim.
At this moment there seems to be a problem witth the FBW software, but I think they will sort this out eventually. It worked quite fine in the past.

Applications should specify the app id in their manifest or call com.facebook.FacebookSdk#setApplicationId(String) } in their application startup path. For specifying in the manifest, add a meta tag in your tag.

When sharing to Messenger, apps should call the #shareToMessenger method. For example, ShareToMessengerParams params = ShareToMessengerParams.newBuilder(uri, "image/*") .setMetaData(metaData) .build(); MessengerUtils.shareToMessenger(this, REQUEST_CODE_SHARE_TO_MESSENGER, params); To handle receiving a composer shortcut or reply intent from Messenger, apps should put the following intent filter in their manifest for the activity that receives the intent: When handling the intent, then call #getMessengerThreadParamsForIntent to receive the parameters for messenger. When the user has clicked the Send button to send the content to Messenger, then call #finishShareToMessenger to return the data back to Messenger.

7fc3f7cf58
Reply all
Reply to author
Forward
0 new messages