Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Instagram Direct Message handling #21

Merged
merged 16 commits into from
Nov 29, 2023
Merged

Conversation

colinmccloskey
Copy link
Contributor

@colinmccloskey colinmccloskey commented Nov 21, 2023

Adding the ability to handle instagram webhooks into the Facebook Message Handler - major differences are the FB page ID must be used for the call and message echos (notifs when the page sends a message) are sent along with messages, not a separate webhook subscription

IG needs to be sent to the messaging parent (FB) page ID instead of the IG ID, but the webhook contains the IG ID, so for now we default to sending to me/messages which infers the right page from the Access Token
@@ -44,6 +44,7 @@ public class FBMessageHandler implements MessageHandler<FBMessage> {
private final String appSecret;

private final String accessToken;
private final Boolean isInstagram;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in general you want to use primitives bool where possible because it is not possible for them to be null

@@ -44,6 +44,7 @@ public class FBMessageHandler implements MessageHandler<FBMessage> {
private final String appSecret;

private final String accessToken;
@Nullable private final String connectedFacebookPageForInstagram;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@Nullable private final String connectedFacebookPageForInstagram;
private final @Nullable String connectedFacebookPageForInstagram;

This just keeps the reformatting from adding a newline

@@ -10,60 +10,77 @@

import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Preconditions;
import org.jetbrains.annotations.Nullable;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong Nullable, you want the Nullable from the checker framework

Comment on lines 83 to 84
public String connectedFacebookPageForInstagram() {
return connectedFacebookPageForInstagram;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public String connectedFacebookPageForInstagram() {
return connectedFacebookPageForInstagram;
public Optional<String> connectedFacebookPageForInstagram() {
return Optional.ofNullable(connectedFacebookPageForInstagram);

pretty sure this the right code, but you want a return an Optional where possible for nullable values from functions

Comment on lines 24 to 25
@Nullable
private final String connectedFacebookPageForInstagram;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@Nullable
private final String connectedFacebookPageForInstagram;
private final @Nullable String connectedFacebookPageForInstagram;

:)

return pageAccessToken;
}

public @Nullable Optional<String> connectedFacebookPageForInstagram() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public @Nullable Optional<String> connectedFacebookPageForInstagram() {
public Optional<String> connectedFacebookPageForInstagram() {

@colinmccloskey colinmccloskey merged commit 5e64d23 into main Nov 29, 2023
3 checks passed
@colinmccloskey colinmccloskey deleted the mccloskey/instagram branch November 29, 2023 18:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants