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

topic subscriptions #6

Closed
tugorez opened this issue May 3, 2018 · 3 comments
Closed

topic subscriptions #6

tugorez opened this issue May 3, 2018 · 3 comments

Comments

@tugorez
Copy link

tugorez commented May 3, 2018

Is it possible with the current api to subscribe users to a topic?

@shufo
Copy link
Owner

shufo commented May 4, 2018

@tugorez
Sorry, currently subscribe users to a topic is not supported by fcmex.

But there is api for manage relaationship maps in FCM.
https://developers.google.com/instance-id/reference/server#create_relationship_maps_for_app_instances
You can use this api for managing subscription for a topic.

I'm planning to implement this by fcmex in next version!

@shufo
Copy link
Owner

shufo commented May 4, 2018

@tugorez

Topic subscription added in fcmex 0.2.0.
Now you can subscribe users to a topic.

def deps do
  [{:fcmex, "~> 0.2.0"}]
end

Usage

# create a subscription
{:ok, result} = Fcmex.Subscription.subscribe("topic_name", "fcm_token")

# get subscription information related with specified token
{:ok, result} = Fcmex.Subscription.get("fcm_token")
iex> result
 %{
   "application" => "application_name",
   "applicationVersion" => "3.6.1",
   "authorizedEntity" => "1234567890",
   "platform" => "IOS",
   "rel" => %{"topics" => %{"test_topic" => %{"addDate" => "2018-05-03"}}},
   "scope" => "*"
 }}

# create multiple subscriptions
{:ok, result} = Fcmex.Subscription.subscribe("topic_name", ["fcm_token", "fcm_token2"])

# unsubscribe a topic
{:ok, result} = Fcmex.Subscription.unsubscribe("topic_name", "fcm_token")

# batch unsubscribe from a topic
{:ok, result} = Fcmex.Subscription.unsubscribe("topic_name", ["fcm_token", "fcm_token2"])

push to the topic

{:ok, body} = Fcmex.push("/topics/topic_name",
  notification: %{
    title: "foo",
    body: "bar",
    click_action: "open_foo",
    icon: "new",
  }
)

@tugorez
Copy link
Author

tugorez commented May 4, 2018

OMG it was really fast :) thank you very much for your help @shufo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants