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

Facebook lead ads #330

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
180 changes: 180 additions & 0 deletions connectors/sink-facebook-lead-ads/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
---
title: Facebook Lead Ads
---

# Facebook Lead Ads Sink

## Introduction

The Facebook Lead Ads Sink is a [Vanus Connector][vc] that aims to handle incoming CloudEvents in a way that extracts the `data`
part of the original event and <must: description...>

For example, the incoming CloudEvent looks like this:

```json
{
"id": "88767821-92c2-477d-9a6f-bfdfbed19c6a",
"source": "quickstart",
"specversion": "1.0",
"type": "test",
"time": "2022-07-08T03:17:03.139Z",
"datacontenttype": "application/json",
"data": {
"name": "Vanus Community",
"follow_up_action_url": "<follow_up_action_URL>",
"questions": {
{
"type": "FIRST_NAME"
},
{
"type": "LAST_NAME"
},
{
"type": "EMAIL"
},
}
"privacy_policy": {
"url": "<Policy_URL>"
}
}
}
```

The Facebook Lead Ads Sink will create a form name ``Vanus Community`` with fields for ``first_name``, ``last_name`` and ``email address``.

## Quickstart

<optional prerequisites but recommended>
### Prerequisites
- Have a container runtime (i.e., docker).
- ...
</optional>

### Create the config file

<optional: explanation>

```shell
cat << EOF > config.yml
<example config content>
...
EOF
```

| Name | Required | Default | Description |
|:-----|:---------:|:--------|---------------------------------------|
| port | NO | 8080 | the port which <name> Sink listens on |

...

The <name> Sink tries to find the config file at `/vanus-connect/config/config.yml` by default. You can specify the
position of config file by setting the environment variable `CONNECTOR_CONFIG` for your connector.

### Start with Docker

```shell
docker run -it --rm \
-p 31080:8080 \
-v ${PWD}:/vanus-connect/config \
--name sink-<name> public.ecr.aws/vanus/connector/sink-<name>
```

### Test

<option: explanation>.

Open a terminal and use following command to send a CloudEvent to the Sink.

```shell
curl --location --request POST 'localhost:31080' \
--header 'Content-Type: application/cloudevents+json' \
--data-raw '{
<incoming event example>
}'
```

<show result with a paragraph>

### Clean resource

```shell
docker stop sink-<name>
```

## Sink details

<optional>
### Extension Attributes

The <name> Sink have additional reactions if the incoming CloudEvent contains
following[Extension Attributes](https://github.com/cloudevents/spec/blob/main/cloudevents/spec.md#extension-context-attributes)
.

| Attribute | Required | Examples | Description |
|:---------------|:--------:|:----------|:--------------------------------------|

...
</optional>

### Data format

The <name> Sink requires following data format in CloudEvent's `data` field.

```json
{
<full example>
}
```

<optional>
### Examples

#### Example1

```shell
curl --location --request POST 'localhost:31080' \
--header 'Content-Type: application/cloudevents+json' \
--data-raw '{
"id": "53d1c340-551a-11ed-96c7-8b504d95037c",
"source": "quick-start",
"specversion": "1.0",
"type": "sink-<name>",
"datacontenttype": "application/json",
"time": "2022-10-26T10:38:29.345Z",
"data": {
<data1>
}
}'
```

#### example2

```shell
curl --location --request POST 'localhost:31080' \
--header 'Content-Type: application/cloudevents+json' \
--data-raw '{
"id": "53d1c340-551a-11ed-96c7-8b504d95037c",
"source": "quick-start",
"specversion": "1.0",
"type": "sink-<name>",
"datacontenttype": "application/json",
"time": "2022-10-26T10:38:29.345Z",
"<extension_attr1>": "test",
"<extension_attr2>": "test",
"data": {
<data2>
}
}'
```

## Run in Kubernetes

```shell
kubectl apply -f sink-<name>.yaml
```

```yaml
<must: content>
```

[vc]: https://www.vanus.dev/introduction/concepts#vanus-connect
24 changes: 24 additions & 0 deletions connectors/sink-facebook-lead-ads/cmd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2023 Linkall Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package main

import (
cdkgo "github.com/vanus-labs/cdk-go"
"github.com/vanus-labs/connector/sink/facebook-lead-ads/internal"
)

func main() {
cdkgo.RunSink(internal.NewFacebookLeadAdsConfig, internal.NewFacebookLeadAdsSink)
}
41 changes: 41 additions & 0 deletions connectors/sink-facebook-lead-ads/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
module github.com/vanus-labs/connector/sink/facebook-lead-ads/internal

go 1.18

require (
github.com/cloudevents/sdk-go/v2 v2.13.0
github.com/vanus-labs/cdk-go v0.5.0
)

require (
github.com/coreos/go-semver v0.3.0 // indirect
github.com/coreos/go-systemd/v22 v22.3.2 // indirect
github.com/go-playground/locales v0.14.0 // indirect
github.com/go-playground/universal-translator v0.18.0 // indirect
github.com/go-playground/validator/v10 v10.11.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/uuid v1.1.2 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
github.com/huandu/facebook/v2 v2.7.0 // indirect
github.com/json-iterator/go v1.1.11 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
go.etcd.io/etcd/api/v3 v3.5.6 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.5.6 // indirect
go.etcd.io/etcd/client/v3 v3.5.6 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/zap v1.17.0 // indirect
golang.org/x/crypto v0.0.0-20220314234659-1baeb1ce4c0b // indirect
golang.org/x/net v0.7.0 // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/text v0.7.0 // indirect
google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c // indirect
google.golang.org/grpc v1.41.0 // indirect
google.golang.org/protobuf v1.26.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading