Nodes:
name: Setup
type: n8n-nodes-base.set
parameters: fields: values: linkedInAPIKey
twitterAPIKey
emails
name: Every morning @ 7
type: n8n-nodes-base.scheduleTrigger
parameters: rule: interval: 7
name: Get meetings for today
type: n8n-nodes-base.googleCalendar
parameters: options: timeMax: ={{ $today.plus({ days: 1 }) }}
timeMin: ={{ $today.minus({ days: 3 }) }}
singleEvents: yes
calendar: __rl: yes
mode: list
value: milorad.filipovic19@gmail.com
cachedResultName: milorad.filipovic19@gmail.com
operation: getAll
name: Get attendees email domains
type: n8n-nodes-base.set
parameters: fields: values: name: domain
type: arrayValue
arrayValue: ={{ $json.attendees.filter(a => !a.organizer).map(a => a.email.split('@').pop()) }}
name: attendeeEmails
type: arrayValue
arrayValue: ={{ $json.attendees.filter(a => !a.organizer).map(a => a.email) }}
name: Split Out
type: n8n-nodes-base.splitOut
parameters: include: selectedOtherFields
fieldToSplitOut: domain
fieldsToInclude: attendeeEmails, start
name: Get recent LinkedIn posts
type: n8n-nodes-base.httpRequest
parameters: url: https://fresh-linkedin-profile-data.p.rapidapi.com/get-company-posts
sendQuery: yes
sendHeaders: yes
queryParameters: parameters: name: linkedin_url
value: =https://www.linkedin.com/{{ $json.linkedin.handle }}
name: sort_by
value: recent
headerParameters: parameters: name: X-RapidAPI-Key
value: ={{ $('Setup').item.json.linkedInAPIKey }}
name: X-RapidAPI-Host
value: fresh-linkedin-profile-data.p.rapidapi.com
name: Enrich attendee company
type: n8n-nodes-base.clearbit
parameters: domain: ={{ $json.domain }}
name: Gmail
type: n8n-nodes-base.gmail
parameters: sendTo: ={{ $('Setup').first().json.emails }}
message: ={{ $json.html }}
subject: =Latest social activity for: {{ $('Wrap everything together').item.json.name }}
name: Combine all activity for a company
type: n8n-nodes-base.merge
parameters: mode: combine
options: clashHandling: values: resolveClash: preferInput2
joinMode: keepEverything
mergeByFields: values: field1: name
field2: name
name: Extract data for email
type: n8n-nodes-base.set
parameters: fields: values: name: attendeeEmail
stringValue: ={{ $json.meeting.attendeeEmails.find(a => a.endsWith($json.meeting.domain)) }}
name: startHour
type: numberValue
numberValue: ={{ DateTime.fromISO($json.meeting.start.dateTime).hour }}
name: startMinute
type: numberValue
numberValue: ={{ DateTime.fromISO($json.meeting.start.dateTime).minute }}
include: selected
includeFields: name, html_twitter, html_linkedin
name: Prepare email template
type: n8n-nodes-base.html
parameters: html: <!DOCTYPE html>

<html>
<head>
  <meta charset="UTF-8" />

</head>
<body>
  <div class="container">
     <h2 style="font-size: 1.2em">
      🗓️ Meeting with <span>{{ $json.attendeeEmail }}</span>
       at {{ $json.startHour }}:{{ $json.startMinute < 10 ? `0${$json.startMinute}` : $json.startMinute }}h
       <h3>Here's a quick summary of {{ $json.name }}'s recent social media activities</h3>
       <p class="summary">
         {{ $json.message.content }}
       </p>
    </h2>

  </div>
</body>
</html>

<style>
.container {
  font-family: sans-serif;
}

.summary {
  background-color: #f7f9fc; 
  font-family: sans-serif; 
  padding: 0.3em 1em
}
</style>
name: Sticky Note
type: n8n-nodes-base.stickyNote
parameters: color: 7
width: 409.31582584657923
height: 426.61520915049425
content: ## Start here
1️⃣ Register on [RapidAPI](https://rapidapi.com) and subscribe to these two APIs:
- [Fresh LinkedIn Profile Data](https://rapidapi.com/freshdata-freshdata-default/api/fresh-linkedin-profile-data)
- [Twitter](https://rapidapi.com/omarmhaimdat/api/twitter154)


2️⃣ Set API keys for these two in `linkedInAPIKey` and `twitterAPIKey`fields of this node

3️⃣ Set email addresses that should receive the list in the `emails` field of this node
name: Sticky Note1
type: n8n-nodes-base.stickyNote
parameters: color: 7
width: 334.90628250854803
height: 282.9114150520537
content: 













ℹ️ If you need to get activities from more social media accounts found by ClearBit, they can be added here, just make sure to process them properly in separate switch node branches
name: Keep only ones with the domain
type: n8n-nodes-base.filter
parameters: conditions: options: caseSensitive: yes
typeValidation: strict
combinator: and
conditions: operator: type: string
operation: exists
singleValue: yes
leftValue: ={{ $json.domain }}
name: Extract important data
type: n8n-nodes-base.set
parameters: fields: values: name: linkedin_posts
type: arrayValue
arrayValue: ={{ $input.item.json.data.slice(0, 10).map(d => { return { text: d.text, likes: d.num_likes, comments: d.num_comments, postedAt: d.posted } } ) }}
name: name
stringValue: ={{ $('Switch').item.json.name }}
name: meeting
type: objectValue
objectValue: ={{ $('Split Out').item.json }}
include: none
name: Extract important data again
type: n8n-nodes-base.set
parameters: fields: values: name: twitter_posts
type: arrayValue
arrayValue: ={{ $input.item.json.results.map(d => { return { text: d.text, favorites: d.favorite_count, retweets: d.retweet_count, replies: d.reply_count, postedAt: d.creationDate} }) }}
name: name
stringValue: ={{ $('Switch').item.json.name }}
name: meeting
type: objectValue
objectValue: ={{ $('Split Out').item.json }}
include: none
name: Ask AI to summerize
type: n8n-nodes-base.openAi
parameters: prompt: messages: =I am a sales representative in my company and I want to see social media activity for a company I am about to meet. I will give you a JSON object  containing company name, and lists of recent LinkedIn and X(Twitter) posts and your job is to give me a summary these posts. This summary needs to be in textual form suitable for email (just the content without the subject and should be impersonal) and should include details interested to a sales representative such as me. JSON data has the following properties: - 'name': Company name, - 'linkedin_posts': List of LinkedIn posts, - 'twitter_posts': List of Twitter posts, You can ignore all other properties in the JSON data. This is the data:
{{ JSON.stringify($json) }}
resource: chat
chatModel: gpt-4
name: Switch
type: n8n-nodes-base.switch
parameters: rules: values: outputKey: linkedin
conditions: options: caseSensitive: yes
typeValidation: strict
combinator: and
conditions: operator: type: boolean
operation: true
singleValue: yes
leftValue: ={{ $json.linkedin.handle !== null }}
renameOutput: yes
outputKey: twitter
conditions: options: caseSensitive: yes
typeValidation: strict
combinator: and
conditions: operator: type: boolean
operation: true
singleValue: yes
leftValue: ={{ $json.twitter.id !== null }}
renameOutput: yes
options: allMatchingOutputs: yes
looseTypeValidation: no
name: Wrap everything together
type: n8n-nodes-base.merge
parameters: mode: combine
combinationMode: mergeByPosition
name: Sticky Note2
type: n8n-nodes-base.stickyNote
parameters: color: 5
width: 738.9631933644362
height: 399.8417061497098
content: ### 📬 You will receive one email for every company in your calendar. These emails will look something like this:

![Email example](https://i.imgur.com/IP2Jw1F.png#full-width)
name: Get latest tweets
type: n8n-nodes-base.httpRequest
parameters: url: https://twitter154.p.rapidapi.com/user/tweets
options: batching: batch: batchSize: 1
batchInterval: 2000
sendQuery: yes
sendHeaders: yes
queryParameters: parameters: name: limit
value: 10
name: user_id
value: ={{ $json.twitter.id }}
name: include_replies
value: ={{ false }}
name: include_pinned
value: ={{ false }}
headerParameters: parameters: name: X-RapidAPI-Host
value: twitter154.p.rapidapi.com
name: X-RapidAPI-Key
value: ={{ $('Setup').first().json.twitterAPIKey }}

Connections:
Setup: main: node: Get meetings for today
type: main
Switch: main: node: Get recent LinkedIn posts
type: main
node: Get latest tweets
type: main
Split Out: main: node: Keep only ones with the domain
type: main
Every morning @ 7: main: node: Setup
type: main
Get latest tweets: main: node: Extract important data again
type: main
Ask AI to summerize: main: node: Wrap everything together
type: main
Extract data for email: main: node: Wrap everything together
type: main
Extract important data: main: node: Combine all activity for a company
type: main
Get meetings for today: main: node: Get attendees email domains
type: main
Prepare email template: main: node: Gmail
type: main
Enrich attendee company: main: node: Switch
type: main
Wrap everything together: main: node: Prepare email template
type: main
Get recent LinkedIn posts: main: node: Extract important data
type: main
Get attendees email domains: main: node: Split Out
type: main
Extract important data again: main: node: Combine all activity for a company
type: main
Keep only ones with the domain: main: node: Enrich attendee company
type: main
Combine all activity for a company: main: node: Ask AI to summerize
type: main
node: Extract data for email
type: main