page_type | description | products | languages | ||||
---|---|---|---|---|---|---|---|
sample |
This sample demonstrates how to use the Microsoft Graph connector API to create a custom connector that indexes issues and repositories from GitHub. |
|
|
Microsoft Graph connectors let you add your own data to the semantic search index and have it power various Microsoft 365 experiences. This TypeScript application shows you how to use the Microsoft Graph connector API to create a custom connector that indexes issues and repositories from GitHub. This connector sample powers experiences such as Microsoft Search, Copilot in Teams, the Microsoft 365 App, and more.
The Microsoft Graph connector experiences that will be enabled in the sample include:
- Microsoft Search
- Context IQ in Outlook on the web
- Microsoft 365 Copilot
- Microsoft 365 app: Quick Access & My Content
- Type Down Suggestions (Query formulation)
- Simplified admin experience in the Teams admin center (Microsoft 356 App)
- Node.js 18 or higher
- A Microsoft work or school account with the Global administrator role. If you don't have a Microsoft account, you can sign up for the Microsoft 365 Developer Program to get a free Microsoft 365 subscription.
- A GitHub account
If you want to enable the simplified admin experience in the Teams admin center, you will also need the following.
- The devtunnel CLI or ngrok.
- Custom Teams app uploading must be enabled in your Microsoft 365 tenant.
-
Go to the Azure Active Directory admin center and sign in with an administrator account.
-
In the left pane, select Azure Active Directory, and under Manage, select App registrations.
-
Select New registration.
-
Complete the Register an application form with the following values, and then select Register.
- Name:
GitHub Connector
- Supported account types: Accounts in this organizational directory only
- Redirect URI: Leave blank
- Name:
-
On the GitHub Connector overview page, copy the values of Application (client) ID and Directory (tenant) ID. You will need both in the following section.
-
Select API Permissions under Manage.
-
Remove the default User.Read permission under Configured permissions by selecting the ellipses (...) in its row and selecting Remove permission.
-
Select Add a permission, and then select Microsoft Graph.
-
Select Application permissions, and add the following permissions:
- ExternalConnection.ReadWrite.OwnedBy
- ExternalItem.ReadWrite.OwnedBy
-
Select Grant admin consent for..., and then select Yes when prompted.
-
Select Certificates & secrets under Manage, and then select New client secret.
-
Enter a description and choose an expiration time for the secret, and then select Add.
-
Copy and save the new secret. You will need it in the following section.
Important
This client secret is never shown again, so make sure you copy it now.
-
Login to your GitHub account and access your profile page.
-
Select Developer settings.
-
Select Personal access tokens, choose Fine-grained tokens, then select Generate new token.
-
Complete the New fine-grained personal access token form with the following values, then select Generate Token
- Name: Graph Connector
- Expiration: 60 days
- Repository Access: All repositories
- Repository Permissions: Set Issues, Contents and Metadata to Read-only.
-
Copy and save the newly generated token. You will need it in the following section.
-
Open .env and update the following values. Alternatively, make a copy of .env named .env.development and change the values there.
Setting Value CLIENT_ID
The Application (client) ID of your app registration in the Azure portal. CLIENT_SECRET
The client secret of your app registration in the Azure portal. TENANT_ID
The Directory (tenant) ID of your app registration in the Azure portal. GITHUB_REPO_OWNER
The GitHub user or organization to read data from. GITHUB_REPO
The GitHub repository to ingest issues from. Must be owned by the user or organization set in gitHubRepoOwner
.GITHUB_TOKEN
Your GitHub personal access token. PORT_NUMBER
The port number to listen on when using the simplified admin experience in the Teams admin center PLACEHOLDER_USER_ID
A user ID in your Microsoft 365 tenant. You can get the user ID of a user in the Azure portal. Select an Azure Active Directory user and copy the value of their Object ID.
This sample offers two ways of creating a connection. You can create one interactively, selecting steps from the sample's command line menu, or you can create a connector using the simplified admin experience in the Teams admin center.
Note
You do not have to do use both of these methods - once a connection is created, you can continue to the Ingest items section.
In this step, you will build and run the sample as an interactive console app. This code sample will create a new connection, register the schema, and then push GitHub repo or issues into that connection.
- Open your command-line interface (CLI) in the directory where package.json is located.
- Use the command
npm start
to run the sample. - Select [1] Create a connection.
- Enter a unique identifier (alphanumeric characters only), name, and description for that connection.
- Select which GitHub content data will be ingested into the connection (repositories or issues).
- Select [4] Register schema for current connection option, and then wait for the operation to complete.
- Select which schema to use (repositories or issues).
The connection is now ready to ingest items.
There are additional configuration steps to run the sample in simplified admin mode.
The simplified admin experience in the Teams admin center communicates with the sample connector by sending an HTTP POST request. In this section you will create a dev tunnel to allow the Teams admin center to send the POST to the sample running on your local development machine.
-
If you do not have the devtunnel CLI installed, follow these instructions to install.
-
Run the following command to login to the dev tunnel service. You can login with either a Microsoft Azure Active Directory account, a Microsoft account, or a GitHub account.
devtunnel user login
-
Run the following commands to create a tunnel. Copy the Tunnel ID from the output.
devtunnel create --allow-anonymous
-
Run the following command to assign a port to the tunnel. Replace
tunnel-id
with the Tunnel ID copied in the previous step, andport-number
with the HTTP port set in your appsettings.json.devtunnel port create tunnel-id -p port-number
-
Run the following command to host the tunnel. Replace
tunnel-id
with the Tunnel ID copied in the previous step.devtunnel host tunnel-id
-
Copy the URL labeled Connect via browser.
[!NOTE] The output shows two URLs for Connect via browser. Be sure to copy only one of them.
- Make a copy of the sample-manifest.json named manifest.json.
- In manifest.json, replace
YOUR_CLIENT_ID_HERE
with the Application (client) ID of your app registration in the Azure portal. - In manifest.json, replace
YOUR_DEV_TUNNEL_URL_HERE
with your dev tunnel URL. - Create a ZIP file containing manifest.json, color.png, and outline.png.
- Open the Microsoft Teams admin center in your browser.
- Select Teams apps, then Manage apps.
- Select Upload new app.
- Select Upload in the pop-up, then browse to the ZIP file you created in the previous step.
- Follow the prompts to confirm and upload the ZIP file.
- Open your command-line interface (CLI) in the directory where package.json is located.
- Use the command
npm run serve
to run the sample.
- Open the Microsoft Teams admin center in your browser.
- Select Teams apps, then Manage apps.
- Search for "GitHub Connector", then select GitHub Connector Admin-dev.
- Select Graph Connector.
- Toggle on the Connection status.
The connection is now ready to ingest items.
- Use the command
npm start
to run the sample in interactive mode. - Select [2] Select existing connection. Select the connection you created before.
- Select [5] Push items to current connection.
- Select [1] Issues.
In this step, you will create search verticals and result types to customize the search results in Microsoft SharePoint, Microsoft Office, and Microsoft Search in Bing.
- Sign into the Microsoft 365 admin center by using the global administrator role.
- Select Settings > Search & intelligence > Customizations.
- Select Verticals, then select Add.
- Enter a name in the Name field and select Next.
- Select Connectors, then select the connection you created previously. Select Next.
- On the Add a query page, leave the query blank. Select Next.
- On the Filters page, select Next.
- Select Add Vertical
- Select Enable vertical, then select Done.
Note
It may take a few hours before your new vertical shows up in Microsoft Search.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.