Skip to content

Instantly share code, notes, and snippets.

View looneym's full-sized avatar
🐧
im in ur ifra breakin ur services

Micheál Looney looneym

🐧
im in ur ifra breakin ur services
View GitHub Profile
@looneym
looneym / main.rb
Created February 20, 2017 16:35
Add and remove companies from an Intercom user
# get a user
user = intercom.users.find(email: "bob@example.com")
# add a company to that user
user.companies = [{company_id: 6, name: "Intercom"},]
intercom.users.save(user)
puts user.companies[0].name # "Intercom"
#remove the same company
user.companies = [{company_id: 6, name: "Intercom", remove: true},]
@looneym
looneym / main.js
Created February 15, 2017 11:52
Liquid example
<script>
window.intercomSettings = {
app_id: "hy4aeebl",
name: "{{current_user.name}}", // Full name
email: "{{current_user.email}}", // Email address
created_at: {{current_user.created_at | date: "%s" }}
};
(function(){var w=window;var ic=w.Intercom;if(typeof ic==="function"){ic('reattach_activator');ic('update',intercomSettings);}else{var d=document;var i=function(){i.c(arguments)};i.q=[];i.c=function(args){i.q.push(args)};w.Intercom=i;function l(){var s=d.createElement('script');s.type='text/javascript';s.async=true;s.src='https://widget.intercom.io/widget/hy4aeebl';var x=d.getElementsByTagName('script')[0];x.parentNode.insertBefore(s,x);}if(w.attachEvent){w.attachEvent('onload',l);}else{w.addEventListener('load',l,false);}}})()
from slackclient import SlackClient
from flask import Flask, request
# Slack config
BOT_TOKEN = os.environ['BOTKEY']
CHANNEL_NAME = "intercom-event-notifications"
app = Flask(__name__)
@app.route('/', methods=['POST'])
@looneym
looneym / main.js
Created February 6, 2017 10:25
Conditionally show the messenger based on page URL
URL = window.location.href;
if (URL.includes("terms")){
termsPage = true;
} else {
termsPage = false;
}
var intercomSettings = {
@looneym
looneym / main.js
Created February 3, 2017 11:31
Conditionally add the messenger at certain times.
var currentdate = new Date();
var currentHour = currentDate.getHours();
if (if currentHour > 9 && currentHour < 5)){
window.intercomSettings = {
app_id: APP_ID,
};
}
@looneym
looneym / main.js
Last active January 9, 2017 17:50
Conditionally populate intercomSettings object with user data if user is logged in
if (CurrentUser.loggedIn)){
window.intercomSettings = {
app_id: APP_ID,
name: CurrentUser.Name,
email: CurrentUser.Email,
user_id: CurrentUser.userID,
};
} else {
window.intercomSettings = {
app_id: APP_ID,
@looneym
looneym / main.py
Created December 5, 2016 15:05
Get the body of a POST request using Flask
from flask import Flask, request
app = Flask(__name__)
@app.route('/', methods=['POST'])
def get_body():
req = request.get_data()
print req
return req
@looneym
looneym / main.py
Created December 3, 2016 15:15
How to use a personal access token with the (unofficial) Python SDK
from intercom import Intercom, User
# Standard configuration using an app_id and API Key
Intercom.app_id = "my_app_id"
Intercom.app_api_key = "my-super-secret-api-key"
# Usng a Personal Access Token (jus replace the app_id and leave the key blank)
Intercom.app_id = "my-super-secret-PAT"
# Do whatever
@looneym
looneym / list_comprehension_example.py
Created December 1, 2016 22:58
Simple example showing list comprehensions in Python
class Car:
cars = []
def __init__(self, num, cheap, red, broken):
self.num = num
self.cheap = cheap
self.red = red
self.broken = broken
# client code
require 'intercom'
#replace with your values
intercom = Intercom::Client.new(token: 'my_token')
convos = intercom.conversations.find_all(user_id: 'some_user_id', type: 'user')
convos.each { |x| puts x.id }
# sample output one
===> looneym ~/ruby-api-test ruby test.rb