此内容没有您所选择的语言版本。

Chapter 3. Implement a Twitter to Salesforce sample integration


This sample integration watches Twitter for tweets that mention a particular Twitter user. When the integration finds such tweets, it filters them so that only those tweets that contain the text you specify cause the integration to continue.

For tweets that contain the specified text, the integration passes data related to the tweet, including the Twitter user name, to Salesforce and Salesforce creates a new contact.

Prerequisites

  • You need a Twitter developer account. If you do not already have one, go to https://apps.twitter.com, sign in to Twitter, and click Apply for a developer account. Obtaining the developer account is quick when you provide a professional email address, such as me@redhat.com rather than a personal address such as you@gmail.com.
  • You need an account in a Salesforce installation that is used for development. This account must have Salesforce API access, which is available in a Salesforce Enterprise account or a Salesforce Developer account. To obtain a free developer account, visit https://developer.salesforce.com/signup. It takes less than two minutes to obtain a Salesforce account.
  • You must be logged in to your Fuse Online environment. If you are not already logged in, see What to expect the first time you use Fuse Online.

To implement, deploy, and test this sample integration, the main steps are:

3.1. Register Fuse Online as a Twitter client application

In an integration, to connect to Twitter, the first thing you must do is register your Fuse Online environment as a client application that can access Twitter. This lets you create any number of integrations that connect to Twitter. In other words, you need to register a particular Fuse Online environment with Twitter only once.

In each Fuse Online environment, there can be only one registration of Fuse Online as a Twitter client application. However, while each Twitter connection uses the same registration, it can use different user credentials.

Prerequisite

You are logged in to Fuse Online. The URL for accessing Fuse Online is in the email message that welcomed you to the Red Hat Fuse Online Evaluation program.

Procedure

  1. In Fuse Online:

    1. In the left panel, click Settings.
    2. On the Settings page, near the top, to the right of the callback URL, click Copy Callback URL to copy the callback URL for your installation of Fuse Online to the clipboard. You will need this URL later in this procedure.
    3. To the right of the Twitter entry, click Register to display the Consumer Key and Consumer Secret fields.
  2. In another browser tab, go to your Twitter developer account, sign in if you need to, and do the following:

    1. In the upper right, next to the name of your developer project, click the down caret and click Apps.
    2. In the upper right, click Create an app.
    3. In the App name field, enter a name such as My Fuse Online Client.
    4. In the Application description field, enter a tip such as For leveraging tweets.
    5. In the Website URL field, paste the URL that you copied at the beginning of this procedure and remove api/v1/credentials/callback from the end of the URL.
    6. Select Enable Sign in with Twitter.
    7. In the Callback URLs field, paste the URL again. It should be something like this: https://app-proj9128.7b63.fuse-ignite.openshiftapps.com/api/v1/credentials/callback.
    8. A 100-character description of how you plan to use this app is required. For convenience, you can copy and paste: This is a demo application so that I can evaluate how to integrate Twitter with my enterprise applications.
    9. Click Create.
    10. Click Create again to confirm that you reviewed the developer terms.
    11. At the top of the page for the app you just created, click the Keys and tokens tab.
    12. Copy the API key.
  3. Return to your Fuse Online Settings page and paste the Twitter consumer API key into the Fuse Online Twitter Consumer Key field.
  4. Return to the Twitter Keys and tokens tab and copy the consumer API secret key.
  5. Return to your Fuse Online Settings page and paste the Twitter consumer API secret key into the Fuse Online Twitter Consumer Secret field.
  6. Click Save and then click Ok.

3.2. Create a Twitter connection

To create an integration that obtains data from Twitter, you must first create a Twitter connection. After you create a Twitter connection, you can use it in any number of integrations.

Prerequisites

  • You are logged in to Fuse Online. The URL for accessing Fuse Online is in the email message that welcomed you to the Red Hat Fuse Online Evaluation program.
  • Fuse Online is open in a web browser.
  • You registered your Fuse Online environment as an application that can access Twitter.

Procedure

  1. In Fuse Online, in the left panel, click Connections to display any available connections.
  2. In the upper right, click Create Connection to display the available connectors. A connector is a template that you use to create one or more connections.
  3. Click the Twitter connector.
  4. Click Connect Twitter to display a Twitter authorization page. You might need to log in to Twitter before you see the authorization page.
  5. Click Authorize app to return to Fuse Online.
  6. In the Connection Name field, enter your choice of a name that helps you distinguish this connection from any other connections. For example, enter Twitter Connect 1.
  7. In the Description field, optionally enter any information that is helpful to know about this connection. For example, enter Sample Twitter connection that uses my Twitter login credentials.
  8. In the upper right, click Create to see that the connection you created is now available. If you entered the example name, you would see that Twitter Connect 1 appears as a connection that you can choose to add to an integration.

3.3. Register Fuse Online as a Salesforce client application

In an integration, to connect to Salesforce, the first thing you must do is register your Fuse Online environment as a client application that can access Salesforce. This lets you create any number of integrations that connect to Salesforce. In other words, you need to register a particular Fuse Online environment with Salesforce only once.

In each Fuse Online environment, there can be only one registration of Fuse Online as a Salesforce client application. However, while each Salesforce connection uses the same registration, it can use different user credentials.

If you already registered Fuse Online as a Salesforce client and created a Salesforce connection, skip to Create Twitter to Salesforce integration.

Prerequisite

You are logged in to Fuse Online. The URL for accessing Fuse Online is in the email message that welcomed you to the Red Hat Fuse Online Evaluation program.

Procedure

  1. In Fuse Online:

    1. In the left panel, click Settings.
    2. On the Settings page, near the top, to the right of the callback URL, click Copy Callback URL to copy the callback URL for your Fuse Online environment to the clipboard. You will need this URL toward the end of this procedure.
    3. To the right of the Salesforce entry, click Register to display the Client ID and Client Secret fields.
  2. In another browser tab, log in to your Salesforce account and follow the steps below to create a connected app. These instructions assume that you are using the Salesforce Classic user interface. To switch from the Salesforce Lightning Experience interface, click your profile icon and select Switch to Salesforce Classic. For additional information, see the Salesforce documentation for Create a Connected App.

    1. In Salesforce, in the upper right, click Setup.
    2. In the left panel, select Build > Create > Apps.
    3. Scroll down to Connected Apps and click New.
    4. Enter the required information and then select Enable OAuth Settings.
    5. In the Callback URL field, paste your Fuse Online URL, which you copied at the beginning of this procedure. For example: https://app-proj9128.7b63.fuse-ignite.openshiftapps.com/api/v1/credentials/callback.
    6. For OAuth Scopes, add:

      • Access and manage your data (api)
      • Allow access to your unique identifier (openid)
      • Perform requests on your behalf at any time (refresh_token, offline_accesss)
    7. Select Configure ID token and then Include Standard Claims.
    8. Scroll down and click Save.
    9. Scroll up to see that Salesforce indicates a short wait: SF message to wait a few minutes
    10. Click Continue.
    11. Copy the consumer key that Salesforce provides.
  3. Return to your Fuse Online Settings page and paste the Salesforce-provided consumer key into the Fuse Online Salesforce Client ID field.
  4. Return to Salesforce and copy the consumer secret that Salesforce provides.
  5. Return to your Fuse Online Settings page and paste the Salesforce-provided consumer secret into the Fuse Online Salesforce Client Secret field.
  6. Click Save and then click Ok.

3.4. Create a Salesforce connection

To create an integration that accesses data in Salesforce, you must first create a Salesforce connection. After you create a Salesforce connection, you can use it in multiple integrations.

Prerequisites

  • You are logged in to Fuse Online. The URL for accessing Fuse Online is in the email message that welcomed you to the Red Hat Fuse Online Evaluation program.
  • Fuse Online is open in a web browser.
  • You must have already registered your Fuse Online environment as an application that can access Salesforce.

    If you did not already register Fuse Online, see Register with Salesforce.

    Be sure to wait 2 - 10 minutes after registering your Fuse Online installation as a Salesforce client before you try to create a Salesforce connection.

Procedure

  1. In Fuse Online, in the left panel, click Connections to display available connections.
  2. In the upper right, click Create Connection to display the available connectors. A connector is a template for creating one or more connections.
  3. Click the Salesforce connector.
  4. Click Connect Salesforce to display a Salesforce authorization page. You might need to log in to Salesforce before you see the authorization page.

    Note

    The following error indicates that Salesforce does not have the correct Fuse Online callback URL:

    error=redirect_uri_mismatch&error_description=redirect_uri%20must%20match%20configuration

    If you get this error message, then in Salesforce, ensure that the Fuse Online callback URL is specified according to the instructions in Register with Salesforce.

  5. Click Allow to return to Fuse Online.
  6. In the Connection Name field, enter your choice of a name that helps you distinguish this connection from any other connections. For example, enter SF Connect 1.
  7. In the Description field, optionally enter any information that is helpful to know about this connection. For example, enter Sample Salesforce connection that uses my Salesforce login credentials.
  8. In the upper right, click Create to see that the connection you created is now available. If you entered the example name, you would see that SF Connect 1 appears as a connection that you can choose to add to an integration.

3.5. Create and deploy Twitter to Salesforce sample integration

To create and deploy an integration that uses the Twitter and Salesforce connections that you created, the main steps are:

Prerequisites

  • You registered your Fuse Online environment as a Twitter client and created a Fuse Online Twitter connection.
  • You registered your Fuse Online environment as a Salesforce client and created a Fuse Online Salesforce connection.
  • Fuse Online is open and you are logged in.

3.5.1. Choose the start connection

In Fuse Online, to create the sample Twitter to Salesforce integration, the first task is to choose the start connection.

Prerequisites

  • You created a Twitter connection.

Procedure

  1. On the left, click Integrations.
  2. In the upper right, click Create Integration.
  3. On the Choose a Start Connection page, click the Twitter connection you created. If you gave it the example name, you would click Twitter Connect 1. When the integration starts, it uses the credentials defined in this connection to connect to Twitter.
  4. On the Choose an Action page, click Mention.

Next step

When the integration is running, after connecting to Twitter, the integration monitors Twitter for mentions that include your Twitter screen name. A match triggers the next step in the integration. However, before you add steps that operate on data between connections, you choose the connection that the integration uses to finish its work.

3.5.2. Choose the finish connection

In Fuse Online, to continue creating the Twitter to Salesforce sample integration, after you add the start connection, you add the finish connection to the integration.

Prerequisites

  • You added the Twitter connection to the integration as the start connection.
  • Fuse Online is prompting you to add the finish connection.
  • You created a Salesforce connection.

Procedure

  1. On the Choose a Finish Connection page, click the Salesforce connection that you created. If you gave it the example name, you would click SF Connect 1. This integration finishes by using the credentials defined in this connection to connect to Salesforce.
  2. On the Choose an Action page, click New record.
  3. On the New record page, click in the Object name field and select Contact as the Salesforce record to create.
  4. Click Done to add the finish connection to the integration.

3.5.3. Add a basic filter step

In Fuse Online, to continue creating the Twitter to Salesforce sample integration, add a basic filter step that checks tweets that mention you for particular content. At integration execution time, processing continues only if that content is present.

Prerequisites

  • You added the Twitter connection as the integration’s start connection.
  • You just added the Salesforce connection as the integration’s finish connection.

Procedure

  1. In the main panel, click Add a step.
  2. Click Basic Filter.
  3. In the first field (The data you want to evaluate), start to enter text and when text appears below the field, click it. This indicates that the content to filter for is in the Twitter text field, which contains the text of the tweet.
  4. Accept contains as the condition to be met for the integration to continue.
  5. In the last field, enter #RedHatIsGreat or some other text you choose. A tweet that mentions you must contain the text you enter here for the integration to continue operating on this data.
  6. Click Done to complete the basic filter step.

3.5.4. Add a data mapping step

To continue creating the Twitter to Salesforce sample integration, add a data mapping step that correlates Twitter mention fields to Salesforce contact fields.

Prerequisites

  • The integration’s start connection is to Twitter.
  • The integration’s finish connection is to Salesforce.
  • You just added the filter step between the two connections.

Procedure

  1. In Fuse Online, in the left panel, hover over the plus sign between the filter step and the finish connection to display a pop-up in which you click Add a Step.
  2. Click Data Mapper and wait a few moments. When the data fields appear, the Sources panel on the left displays the Twitter fields and the Target panel on the right displays the Salesforce fields.
  3. Map the Twitter name field to the Salesforce FirstName and LastName fields:

    1. In the Sources panel, click the magnifying glass magnifying glass to display the search field and enter name.
    2. Under the user folder, click the name field.
    3. In the Target panel, scroll down and click FirstName. The data mapper displays a line from the source name field to the target FirstName field.
    4. In the Target panel, scroll down, hover over LastName, and press CTRL-Mouse1 (CMD-Mouse1 on MacOS) to select LastName. The data mapper displays another line from the Twitter name field, but this time it goes to the Salesforce LastName field. The blue lines indicate the current focus.

      In the Mapping Details panel, you can see that the data mapper automatically changed the action from Map to Separate.

    Note

    If you accidentally map the wrong fields then delete the incorrect mapping by selecting one of its fields to make it the current mapping. Then click the trash can icon in the top right of the data mapper.

  4. Map the Twitter screenName field to the Salesforce Title field:

    1. In the Sources panel, scroll down to click the screenName field.
    2. On the right, at the top of the Target panel, click the magnifying glass magnifying glass to display the search field and enter Title.
    3. Click the Title field. The data mapper displays a line from the Twitter screenName field to the Salesforce Title field.
  5. Map the Twitter text field to the Salesforce Description field:

    1. In the Sources search field, enter text and click the text field. Be sure to click the toplevel text field. Do not click one of the text fields that is contained in the user field.
    2. In the Target search field, enter description.
    3. Click the Salesforce Description field to create the mapping.
  6. In the upper right, click the grid icon grid to display the list of mappings, which should look like this: Data Mappings
  7. In the upper right, click Done.

3.5.5. Give the integration a name and deploy it

When the Twitter to Salesforce sample integration is complete then you can deploy it and see how it works.

Prerequisites

  • The integration’s start connection is Twitter.
  • The integration’s finish connection is Salesforce.
  • The integration has a filter step.
  • You just added a data mapping step to the integration.

Procedure

  1. In Fuse Online, at the top of the left panel, in the Integration Name field, enter a name of your choice that distinguishes this integration from any other integrations. For example: Twitter to Salesforce Sample Integration.
  2. In the upper right corner, click Publish.

    Fuse Online displays the integration summary page with a progress indicator that shows the publishing stages. Fuse Online is generating the runtime for the integration and will start it when the runtime is ready. This takes a few minutes.

    A Fuse Online account is limited to a specific number of integrations that can be running at one time. For details, see the pricing plan. If you are already running the maximum number of integrations, then you must stop an integration before you can start running another one.

    If you are using a Fuse Online evaluation account, then only one integration at a time can be running. If you already created one of the other sample integrations and that integration is running then this integration is automatically in the Stopped state. You must stop the running integration and then you can then publish this integration.

  3. If you are already running the maximum number of integrations, follow these steps to stop an integration:

    1. In the left panel, click Integrations.
    2. In the entry for the integration that you want to stop, click ThreeVerticalDotsKebab on the far right.
    3. In the popup, click Stop.
  4. After stopping an integration, start another integration as follows:

    1. In the left panel, click Integrations.
    2. In the entry for the integration that you want to start, click ThreeVerticalDotsKebab on the far right.
    3. In the popup, click Publish.

3.6. Confirm that the Twitter to Salesforce integration works

To confirm that the Twitter to Salesforce sample integration is working, tweet some messages and check for results in Salesforce.

Prerequisites

  • In Fuse Online, Running appears next to the name that you specified for the Twitter to Salesforce sample integration when you published it.
  • You can access your Twitter and Salesforce accounts.

Procedure

  1. In Fuse Online in the panel on the left, click Integrations to see that the integration you created is a Running integration. If you entered the example name, you would see that Twitter to Salesforce Sample Integration is running.
  2. Confirm that the integration does not create a contact record when a tweet does not contain the text you specified in the basic filter step:

    1. In Twitter, send a tweet that:

      • Mentions your Twitter handle
      • Does not contain the text you specified in the basic filter step

        For example: @Aslan #likesRedHat.

    2. Wait for the polling interval to elapse, which can be 30 - 60 seconds.
    3. In Salesforce, confirm that there is not a new contact record for the name that is associated with the Twitter account that you used to tweet.
  3. Confirm that the integration creates a new contact record when it should:

    1. In Twitter, send a tweet that:

      • Mentions your Twitter handle
      • Contains the text that you specified in the basic filter step

        For example: @Aslan knows #RedHatIsGreat.

    2. Wait for the polling interval to elapse.
    3. In Salesforce, do the following:

      1. Log in to your regular Salesforce account, not your Salesforce developer account.
      2. On your home page, under Recent Items you should see your new contact.
      3. Click on it to view the details.

        The new contact record should have the name that is associated with the Twitter account that you used to tweet. The text of your tweet should be in the Description field, and your Twitter screen name should be in the Title field.

  4. Optionally, view the integration log to troubleshoot an unexpected result or to learn more about integration execution:

    1. In Fuse Online, in the left panel, click Integrations.
    2. Click the entry for your Twitter to Salesforce integration.
    3. In the integration’s summary page, click the Activity tab.
    4. Optionally, enter date and/or keyword filters to limit the executions listed.
    5. Click the integration execution for which you want to view activity information.

3.7. Clean up your integration

When you are done working with a sample integration, you should stop it and delete it so that you can use the resources for another integration.

Prerequisites

  • You are finished working with a sample integration that you published.

Procedure

  1. In Fuse Online, in the left panel, click Integrations.
  2. In the main panel, identify the entry for the sample integration that you want to stop.
  3. In that entry, to the right, click Kebab Menu and then click Stop.
  4. Click Stop to confirm that you want to stop running the integration.
  5. In the entry for the integration that you just stopped, to the right, click Kebab Menu and then click Delete.
  6. Click Delete to confirm that you want to delete the integration.
Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.